neeyum-auth-module
v1.2.0
Published
A React Native authentication module with OTP-first login and password support
Maintainers
Readme
Neeyum Auth Module
A React Native authentication module with phone number, OTP, and password support.
Features
- OTP-first login flow
- Password login option
- OTP-based registration flow
- Automatic registration for new users
- Email verification during registration
- Bilingual support (English/Tamil)
- TypeScript support
- React Navigation integration
- AsyncStorage for token persistence
Installation
npm install neeyum-auth-modulePeer Dependencies
Make sure you have these installed in your project:
npm install @react-navigation/native @react-navigation/stack @react-native-async-storage/async-storageUsage
1. Wrap your app with AuthProvider
import { AuthProvider, AuthNavigator } from 'neeyum-auth-module';
export default function App() {
return (
<NavigationContainer>
<AuthProvider>
<AuthNavigator />
</AuthProvider>
</NavigationContainer>
);
}2. Use the auth hook in your components
import { useAuth } from 'neeyum-auth-module';
function MyComponent() {
const { login, register, requestOTP, t, state } = useAuth();
// Use the auth functions and state
}3. Available Functions
login(credentials: { phone: string; password?: string; otp?: string })- Login with OTP or passwordregister(credentials: { phone: string; name: string; email: string; password: string; otp: string })- Register with OTP verificationrequestOTP(phone: string)- Request OTP for login or registrationlogout()- Logout current usersetLanguage(language: { code: string; name: string })- Change languaget(key: string)- Translation function
4. Authentication Flow
Login (OTP First)
- User enters phone number
- User requests OTP
- User enters OTP to login
- Option to switch to password login if preferred
Password Login (Alternative)
- User switches to password login
- User enters phone number and password
- Option to switch back to OTP login
Registration (via OTP)
- User enters phone number and requests OTP
- If phone number doesn't exist, user is redirected to registration
- User fills in required fields:
- Name
- Password (minimum 6 characters)
- OTP verification
- After successful registration, user can login with OTP or password
Configuration
Replace the API URLs in the AuthContext with your backend endpoints:
// In your app
const response = await fetch('YOUR_API_URL/login', ...);
const response = await fetch('YOUR_API_URL/register', ...);
const response = await fetch('YOUR_API_URL/request-otp', ...);License
MIT
