Skip to main content

User sessions

When loading your application, you might want to check if the user already has a session.

To do so, you can use the getUserSession API

getUserSession(options): Promise<User | null>#

  • options (object)
    • signInIfExists (boolean) If set, the user will be automatically signed in if they have a session

Returns null if no session exists, or an object with id, userName and token if it does exist.

note

This API also works for anonymous users

Example

const client = new CollabClient({ ... });
const checkLogin = async () => {
const user = await client.getUserSession({ signInIfExists: true });
if(user) {
window.location.href = `/profile/${user.id}`;
} else {
window.location.href = '/login';
}
}
checkLogin();