@easyappkit/firebase-auth
v1.0.0
Published
Firebase authentication with hooks and providers for Easy App Kit
Downloads
104
Maintainers
Readme
@easyappkit/firebase-auth
Firebase authentication with React hooks and providers for Easy App Kit.
Installation
npm install @easyappkit/firebase-auth @easyappkit/firebase-config firebaseUsage
Setup
Wrap your app with AuthProvider:
import { AuthProvider } from '@easyappkit/firebase-auth';
import { initializeFirebase } from '@easyappkit/firebase-config';
initializeFirebase({ /* your config */ });
function App() {
return (
<AuthProvider>
{/* Your app */}
</AuthProvider>
);
}Use Authentication
import { useAuth } from '@easyappkit/firebase-auth';
function LoginScreen() {
const { signIn, user, loading } = useAuth();
const handleLogin = async () => {
try {
await signIn('[email protected]', 'password');
} catch (error) {
console.error(error);
}
};
if (loading) return <Text>Loading...</Text>;
if (user) return <Text>Welcome {user.email}</Text>;
return <Button onPress={handleLogin}>Sign In</Button>;
}Get Current User
import { useUser } from '@easyappkit/firebase-auth';
function Profile() {
const user = useUser();
if (!user) return <Text>Not logged in</Text>;
return <Text>{user.displayName || user.email}</Text>;
}API
Hooks
useAuth()
Returns authentication context with:
user: Current user or nullloading: Whether auth state is loadingsignIn(email, password): Sign in usersignUp(email, password): Create new usersignOut(): Sign out current userresetPassword(email): Send password reset email
useUser()
Returns current user or null.
Services
import { signIn, signUp, signOut, resetPassword } from '@easyappkit/firebase-auth';
await signIn('[email protected]', 'password');
await signUp('[email protected]', 'password');
await signOut();
await resetPassword('[email protected]');License
MIT
