Svelte Firekit: Auth
Authentication
Authentication methods and user management for Svelte-Firekit.
The firekitAuth service provides methods for handling user authentication in your Svelte application. It includes support for Google authentication, email/password authentication, and user profile management.
Usage
import { firekitAuth } from 'svelte-firekit'; Methods
Google Authentication
await firekitAuth.signInWithGoogle() Signs in a user using Google OAuth. Automatically creates/updates the user’s Firestore profile.
Email/Password Authentication
await firekitAuth.signInWithEmail(email: string, password: string) Signs in a user with email and password.
await firekitAuth.registerWithEmail(
  email: string, 
  password: string, 
  displayName: string
) Registers a new user with email and password. Automatically sends email verification and creates a Firestore profile.
User Management
await firekitAuth.logOut() Signs out the current user.
await firekitAuth.sendPasswordReset(email: string) Sends a password reset email to the specified address.
await firekitAuth.sendEmailVerificationToUser() Sends an email verification to the current user.
await firekitAuth.updateUserProfile({
  displayName?: string,
  photoURL?: string
}) Updates the current user’s profile information.
await firekitAuth.updateUserPassword(
  newPassword: string, 
  currentPassword: string
) Updates the user’s password. Returns a response object:
success: booleanmessage: stringcode?: string (in case of error)
await firekitAuth.deleteUserAccount() Deletes the current user’s account and associated Firestore data. Returns:
success: booleanmessage: string
Example
// In your Svelte component
async function handleSignIn() {
  try {
    // Sign in with Google
    await firekitAuth.signInWithGoogle();
    
    // Or with email/password
    await firekitAuth.signInWithEmail('[email protected]', 'password');
  } catch (error) {
    console.error('Authentication failed:', error);
  }
}
async function handlePasswordUpdate() {
  const result = await firekitAuth.updateUserPassword(
    'newPassword123', 
    'currentPassword'
  );
  
  if (result.success) {
    console.log(result.message);
  } else {
    console.error(result.message);
  }
} Notes
- All authentication methods automatically sync user data with Firestore
 - Email verification is sent automatically on new user registration
 - User profile updates are automatically synced with Firestore
 - Password updates require reauthentication with current password
 - Account deletion removes both authentication and Firestore data
 
On this page
Need help with your project?
I offer custom development services, consulting, and technical guidance for your web applications.
Let's work together