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(): Promise<User | null>#

Returns null if no session exists, or a User if they are logged in.

note

This API also works for anonymous users

Example

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