AuthProvider
User authentication, registration and sessions.
More information about the module's user interface https://doc.oneentry.cloud/docs/users/auth_provider (opens in a new tab)
The AuthProvider module handles user authentication: sign-up, login, password changes, email and SMS activation codes, OAuth, and keeping the session alive with access and refresh tokens. The SDK supports multiple authentication providers (login and password, and OAuth).
Quickstart
Initialize the module from defineOneEntry:
const { } = defineOneEntry( , { });
Authenticate a user against the email provider and read the returned tokens:
// Authenticate against the "email" auth provider.
const result = await AuthProvider.auth("email", {
authData: [
{ marker: "login", value: "john@example.com" },
{ marker: "password", value: "12345" },
],
});
if ('statusCode' in result) throw new Error(result.message);
// On success the SDK stores the tokens automatically.
console.log(result.accessToken, result.refreshToken);
The first argument is always the provider marker (e.g. "email"). After a successful auth(), the SDK keeps the tokens and refreshes them for you.
Features
| Feature | What It Does | Example Use |
|---|---|---|
| User Registration | Create new user accounts | Sign up form |
| Login / Logout | Authenticate users | Login page |
| Password Management | Change & recover passwords | Forgot password flow |
| Token Management | Keep users logged in securely | Auto-refresh sessions |
| Email / SMS / Push verification | Send activation codes | Verify account after signup |
| OAuth | Social login (Google, etc.) | "Sign in with Google" |
Authentication flow
1. User enters email + password
↓
2. auth() is called with the provider marker
↓
3. OneEntry verifies credentials and returns access + refresh tokens
↓
4. The SDK stores the tokens and sends the access token with requests
↓
5. When the access token expires, the SDK uses the refresh token automatically
Authentication providers
Each auth provider has a type, and you call it by its own marker (for example email):
- Email (type
email): login and password. - Phone (type
phone): sign-in by phone number. - OAuth (type
oauth): Google, Facebook, etc. Set up OAuth providers in the OneEntry admin panel, then use oauth().
In authData, use the markers of the login and password fields of the provider's form (for example login/password or email_reg/password_reg). The login can be an email or a username, whatever your auth provider accepts.
Activation codes can be delivered over email, SMS or push, through the notificationData object you pass to signUp(). phoneSMS and phonePush are delivery channels for those codes, not standalone login providers.
Tokens
A successful auth() returns two tokens:
- Access token: short-lived, sent with API requests. Its lifetime is configured in the admin panel (opens in a new tab).
- Refresh token: long-lived, used to get new access tokens.
You don't need to manage tokens yourself. The SDK stores them, sends the access token with each request, and when the access token expires it uses the refresh token to get a new one, so users stay logged in.
To keep users logged in after a page reload, persist the refresh token with saveFunction:
const { AuthProvider } = defineOneEntry("https://your-project.oneentry.cloud", {
token: "your-app-token",
auth: {
refreshToken: localStorage.getItem('refreshToken') ?? undefined,
saveFunction: (token) => localStorage.setItem('refreshToken', token)
}
});
logout() and logoutAll() invalidate sessions on the server, not just on the client.
Form fields
When you register users, each form data entry has:
marker: the field name (e.g.email_reg,password_reg,last_name)type: the data type (e.g.string,image)value: the value
Methods
| Method | What It Does |
|---|---|
| activateUser() | Activate a user with a one-time code. |
| auth() | Authenticate a user. |
| changePassword() | Reset a password with a one-time code. |
| checkCode() | Check a one-time code. |
| generateCode() | Send a one-time code to the user. |
| getActiveSessionsByMarker() 🔐 | Get the user's active sessions. |
| getAuthProviderByMarker() | Get one auth provider object by marker. |
| getAuthProviders() | Get all auth provider objects. |
| logout() 🔐 | Log the user out. |
| logoutAll() 🔐 | Log the user out on all devices. |
| oauth() | Register or sign in a user via OAuth. |
| refresh() | Refresh the user's tokens. |
| signUp() | Register a user. |
🔐 marks methods that require an authenticated user session.
Related
- Users Module: user profiles and data
- Forms Module: registration and login forms
- FormData Module: form submissions