Authentication
Every basefyio project ships with its own authentication service — a dedicated, isolated user directory for your app's end users. These are not the same as your basefyio dashboard account: your customers sign up and sign in to your application, and basefyio issues them JSON Web Tokens (JWTs) you can use to protect data with Row-Level Security.
You get email & password, email verification, password reset, magic links, and social login (Google, GitHub) out of the box — from the SDK or the REST API.
Setup
Install the SDK and create a client with your project ID and anon key (found under Overview → API Keys in the dashboard). The anon key is safe to ship in a browser; data access is still governed by your RLS policies.
npm install basefyio-jsimport { createClient } from 'basefyio-js'
const bf = createClient({
projectId: 'your-project-id',
apiKey: 'your-anon-key',
})All auth methods live under bf.auth.
Email & password
Sign a new user up, then sign them in. The SDK stores the session and refreshes it automatically.
// Sign up
const { data, error } = await bf.auth.signUp({
email: 'jane@example.com',
password: 'a-strong-password',
firstName: 'Jane', // optional
lastName: 'Doe', // optional
})
// Sign in
const { data, error } = await bf.auth.signIn({
email: 'jane@example.com',
password: 'a-strong-password',
})
// The signed-in user
const { data: user } = await bf.auth.getUser()
// Sign out (clears the local session)
await bf.auth.signOut()Every method returns { data, error } — check error before using data. One account per email is enforced per project, so a duplicate signUp returns an error.
Sessions & tokens
After sign-in the SDK keeps the session in memory and refreshes the access token before it expires. Read it any time, attach a token to your own backend calls, or react to auth changes:
const session = bf.auth.getSession()
const token = bf.auth.getAccessToken() // send as: Authorization: Bearer <token>
// React to sign-in / sign-out / token refresh
const { unsubscribe } = bf.auth.onAuthStateChange((event, session) => {
// event: 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'EMAIL_VERIFIED' | ...
})Email verification
If Require email verification is on (project → Auth → Settings), new users receive a code by email. Confirm it with the OTP they enter:
const { error } = await bf.auth.verifyEmail('482917')Password reset
Send a reset code to the user's email, then set a new password with that code:
// 1. Email the user a reset code
await bf.auth.forgotPassword('jane@example.com')
// 2. User enters the code; set the new password
await bf.auth.resetPassword('482917', 'a-new-strong-password')Magic links (passwordless)
Email a one-time sign-in code, then exchange it for a session:
await bf.auth.sendMagicLink('jane@example.com')
const { data } = await bf.auth.verifyMagicLink('482917')Social login (Google & GitHub)
Once a provider is enabled for your project (see below), start the flow with signInWithProvider. The browser is redirected to the provider and back to your app:
// Kicks off the redirect to Google / GitHub
await bf.auth.signInWithProvider('google', {
redirectTo: '/dashboard', // a path in YOUR app
})
// On the page the user lands back on, finish the flow:
const tokens = bf.auth.handleProviderCallback() // reads the URL, stores the sessionEnabling a provider
In the dashboard open your project → Auth → Providers, pick Google or GitHub, paste the Client ID and Client Secret from the provider's developer console, and enable it.
Important — the redirect URI. In your Google Cloud Console / GitHub OAuth app, the Authorized redirect URI must be the exact URL shown in the Providers panel. basefyio brokers the login through its auth service, so that URL looks like:
https://auth.basefyio.com/realms/<your-realm>/broker/google/endpointCopy it straight from the Providers panel (there's a copy button) — a mismatch here is the #1 reason social login fails with redirect_uri_mismatch.
Managing users from the dashboard
Project → Auth → Users lists everyone who has signed up. You can add a user manually (Add User), reset a password, edit their profile, or remove them. Adding a user with an email that already exists is rejected.
Users imported from Supabase
When a project is imported from Supabase, its users come along with the same user ids they had there. Rows that reference auth.users and policies that compare against auth.uid() keep matching the same people, so a signed-in user sees exactly the data they saw before.
Give the import your Supabase database password (Supabase → Settings → Database) and passwords come along too: users sign in with the email and password they already use, with no reset and no email from you. The first successful bf.auth.signIn checks the password against the one stored at Supabase and keeps it from then on. Without the database password, accounts and ids still arrive, but each user has to reset their password before signing in.
- Email confirmation, bans and sign-up dates carry over. Users without an email address (phone-only or anonymous) are not imported.
- A user who signed in with Google or another provider at Supabase signs in the same way here once the provider is enabled for the project.
- If the project's password rules are stricter than Supabase's, a user whose old password falls short gets the error code
password_reset_requiredand can choose a new one through the password reset flow. - A sync run later adds users created at Supabase since the import and brings over passwords that changed there, for users who have not signed in here yet.
REST API
Not using JavaScript? Every method maps to a REST endpoint under /api/rest/v1/auth/. Send your anon key as the apikey header. Do not put keys in URLs: query strings end up in logs and referrers.
| Method & path | Body | Purpose |
|---|---|---|
POST /api/rest/v1/auth/signup | { email, password, firstName?, lastName? } | Create a user, return tokens |
POST /api/rest/v1/auth/signin | { email, password } | Sign in, return tokens |
POST /api/rest/v1/auth/verify-email | { otp } | Confirm an email code |
POST /api/rest/v1/auth/forgot-password | { email } | Email a reset code |
POST /api/rest/v1/auth/reset-password | { otp, newPassword } | Set a new password |
POST /api/rest/v1/auth/magic-link | { email } | Email a magic-link code |
POST /api/rest/v1/auth/magic-link/verify | { otp } | Exchange code for tokens |
POST /api/rest/v1/auth/refresh | { refreshToken } | Refresh the access token |
GET /api/rest/v1/auth/me | — | Current user (Bearer token) |
GET /api/rest/v1/auth/signin/:provider | — | Start a social-login redirect |
curl -X POST "https://api.basefyio.com/api/rest/v1/auth/signin" \
-H "apikey: YOUR_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"email":"jane@example.com","password":"a-strong-password"}'Using the token to protect data
Send the user's access token with your data requests and basefyio evaluates your Row-Level Security policies as that user — so people only ever read and write the rows they're allowed to. The SDK attaches the token automatically once the user is signed in.