init needs to be the very first thing you call in your web app. It initializes the SDK with your App ID, and it also handles automatic logins when users return to your web app with an active session.
userbase.init({ appId })
.then((session) => {
// SDK initialized successfully
if (session.user) {
// there is a valid active session
console.log(session.user.username)
}
})
.catch((e) => console.error(e))
Parameters
- appId [string] - The App ID you received when you created your Userbase app.
Result
-
session [object] - Contains information about the last used session.
-
user [object] - If set, this contains information about the logged in user.
- username [string] - The user's username.
- email [string] - The user's email.
- profile [object] - The user's profile.
- lastUsedUsername [string] - If set, this is the username of the last user that was logged in.
Errors
- ParamsMustBeObject
- AppIdAlreadySet
- AppIdMustBeString
- AppIdCannotBeBlank
- AppIdNotValid
- UserAlreadySignedIn
- ServiceUnavailable