Skip to main content
You can access auth methods via client.auth. When you call login(), signUp(), or refreshToken(), the module stores the accessToken and refreshToken and uses them for subsequent authenticated requests such as me() or updateProfile(). In the browser, the SDK persists the access token in localStorage under ub_auth_token and the refresh token under ub_refresh_token. On the next page load, both values are read back automatically. Login, signup, and refresh calls send x-refresh-token-mode: header (and, for refresh, x-refresh-token) so cross-domain setups work without relying on HTTP-only cookies.

signUp

Create a new user account.
Example

login

Authenticate an existing user. The returned accessToken is stored internally.
Returns AuthResponse
Example

refreshToken

Rotate the current access token.
  • Browser: Call without arguments. The SDK reads the refresh token stored in localStorage under ub_refresh_token and sends it in the x-refresh-token header. If no stored token is found, the request falls back to credentials: 'include' so any legacy HTTP-only cookie is still honored.
  • Mobile/Node: Pass the refreshToken string manually. The SDK sends it in the x-refresh-token header.
The returned refreshToken, if present, is persisted automatically for the next call.

me

Fetch the profile of the currently authenticated user.

updateProfile

Update the authenticated user’s profile fields.
Example

changePassword

Change the authenticated user’s password.

Social auth

urBackend supports OAuth via GitHub and Google.

socialStart

You receive a URL to initiate the OAuth flow. Redirect your user’s browser to this URL.

socialExchange

Exchange the rtCode received at your callback URL for a refresh token.
Example

Account verification

Use these methods to handle email OTP flows.

publicProfile

Fetch a public-safe profile for any user by their username. This does not return sensitive fields like email or provider IDs.

logout

Call this to revoke your current session on the server and clear the local token.

Manual token management

If you need to manage tokens manually (for example, after social auth or when restoring a session in a non-browser environment), you can use these helper methods:
  • getToken(): Returns the current access token. In the browser, falls back to localStorage.ub_auth_token when the in-memory value is unset.
  • setToken(token?, refreshToken?): Manually set the access token and, optionally, the refresh token. In the browser, both values are also written to localStorage (ub_auth_token and ub_refresh_token). Passing undefined for the access token clears it.
  • getRefreshToken(): Returns the current refresh token. In the browser, falls back to localStorage.ub_refresh_token.
  • setRefreshToken(token?): Manually set or clear the refresh token. In the browser, this also writes to localStorage.ub_refresh_token.