Skip to content

Email & Password

Pulsabase Auth provides native support for email and password authentication, complete with secure bcrypt password hashing, automatic token management, MFA, password resets, and email verification.

Register a new user. On success, the session tokens are automatically stored and the user is immediately signed in.

If your project requires email verification, a confirmation email is automatically sent.

import pb from './pulsabase';
const { user_id, access_token } = await pb.auth.signUpWithPassword(
'user@example.com',
'StrongPassword123!',
{
given_name: 'John',
family_name: 'Doe',
// Optional: store arbitrary metadata
user_metadata: { plan: 'free', referral: 'homepage' },
}
);

Authenticate an existing user. On success, the SDK automatically stores the session tokens and schedules silent refreshes.

const session = await pb.auth.signInWithPassword(
'user@example.com',
'StrongPassword123!'
);
// Handle MFA if enabled for this account
if ('mfa_required' in session) {
const mfaCode = await promptUserForCode();
await pb.auth.signInWithPassword(
'user@example.com',
'StrongPassword123!',
mfaCode // 6-digit TOTP code
);
}

Sign the user out and clear the local session. All SDK requests will become unauthenticated after this call.

await pb.auth.signOut();

A two-step flow for users who have forgotten their password.

Sends an email to the user with a reset link. You configure the link’s destination URL in Dashboard → Settings → Email Templates.

await pb.auth.resetPassword('user@example.com');
// No error is thrown even if the email doesn't exist (security best practice)

When the user clicks the link in their email, extract the token from the URL parameters and call confirmResetPassword.

// On your /reset-password route: ?token=XYZ
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token');
await pb.auth.confirmResetPassword(token, 'NewStrongPassword123!');

If a user is already signed in and wants to change their password, they must provide their current password for security verification.

await pb.auth.updatePassword('CurrentPassword123!', 'NewPassword456!');

If your project requires email verification, users receive a verification email upon registration. You can also re-request the verification email.

// Requires the user to be signed in
await pb.auth.requestEmailVerification();
// token comes from the link in the verification email
await pb.auth.confirmEmailVerification('token_from_email');

Pulsabase supports TOTP-based MFA (compatible with Google Authenticator, Authy, etc.).

const { qr_code_url, recovery_codes } = await pb.auth.mfa.enroll();
// Display qr_code_url to the user for scanning
// Store recovery_codes securely — shown only once!
await pb.auth.mfa.verify('123456'); // 6-digit code from the authenticator app
await pb.auth.mfa.disable();