Accounts and email-and-password sessions
Sign-up, sign-in, the signed-in user and sign-out in the browser with @owbase/web.
Your app’s users belong to the project: each project has its own. In the browser, the Account service handles the account of whoever is using the app. The session lives in a cookie, and every following SDK request is made on behalf of that user.
Before you start, check in Auth → Sign-in methods that Email and password is on.
Sign-up
Section titled “Sign-up”import { Account, ID } from '@owbase/web';import { client } from './client';
const account = new Account(client);
// Creates the account and signs in with it. The session is kept in a browser cookie.await account.create({ userId: ID.unique(), email: '[email protected]', password: 'a-strong-password', name: 'Ana' });await account.createEmailPasswordSession({ email: '[email protected]', password: 'a-strong-password' });
const user = await account.get();console.log(`Hello, ${user.name} (${user.$id})`);create only creates the account; signing in is done by createEmailPasswordSession. To ask for email confirmation, see Verification and recovery.
Sign-in, signed-in user and sign-out
Section titled “Sign-in, signed-in user and sign-out”import { Account } from '@owbase/web';import { client } from './client';
const account = new Account(client);
// Sign in (the account already exists).await account.createEmailPasswordSession({ email: '[email protected]', password: 'a-strong-password' });
// Who is signed in? Without a session, get() fails with 401 (type general_unauthorized_scope).const user = await account.get();console.log(user.email, user.emailVerification ? 'email verified' : 'email not verified');
// Sign out only on this device ('current') or on all of them (deleteSessions).await account.deleteSession({ sessionId: 'current' });account.get()is the way to know whether someone is signed in: without a session, it fails withgeneral_unauthorized_scope(401), because someone who isn’t signed in has no access to the account.deleteSession({ sessionId: 'current' })signs out of this device;deleteSessions()signs out of all of them.- Trying to sign in while a session is already open returns
user_session_already_exists: callget()first.
Password rules
Section titled “Password rules”In Auth → Security you set the minimum length, the blocking of common passwords and the history (prevents reusing the last passwords). The rules apply at sign-up and when changing the password.
On the server
Section titled “On the server”@owbase/node with an API key has no “signed-in user”: it manages the project’s users through the Users service (Users from the server).