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.
login
Authenticate an existing user. The returned accessToken is stored internally.
AuthResponse
refreshToken
Rotate the current access token.
- Browser: Call without arguments. The SDK reads the refresh token stored in
localStorageunderub_refresh_tokenand sends it in thex-refresh-tokenheader. If no stored token is found, the request falls back tocredentials: 'include'so any legacy HTTP-only cookie is still honored. - Mobile/Node: Pass the
refreshTokenstring manually. The SDK sends it in thex-refresh-tokenheader.
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.
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.
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 tolocalStorage.ub_auth_tokenwhen 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 tolocalStorage(ub_auth_tokenandub_refresh_token). Passingundefinedfor the access token clears it.getRefreshToken(): Returns the current refresh token. In the browser, falls back tolocalStorage.ub_refresh_token.setRefreshToken(token?): Manually set or clear the refresh token. In the browser, this also writes tolocalStorage.ub_refresh_token.
