Development Guides
SDK
Authentication

Authentication

Introduction

The generated SDK provides a set of APIs to authenticate users. All authentication APIs on the client side are live by default in the /lib/roq folder, and all authentication APIs are accessible through the ROQ client roqBrowserClient API.

To use it in your application, you need to import it from the SDK:

import { roqBrowserClient } from '@/lib/roq/roq-client';

The API will redirecting users to the sign-in and sign-up pages and clean the session upon logout.

For more information about user registration or authentication, check out this documentation section.

Code examples

Here is code examples for the most important API for authentication: signIn, signUp, and logout.

signIn

Redirect users to the sign-in page.

import { roqBrowserClient } from '@/lib/roq/roq-client';
 
roqBrowserClient.signIn()

signUp

Redirect users to the sign-up page.

import { roqBrowserClient } from '@/lib/roq/roq-client';
 
roqBrowserClient.signUp()

logout

Clean the session.

import { roqBrowserClient } from '@/lib/roq/roq-client';
 
roqBrowserClient.logout()

Framework integration

As mentioned earlier, every successful sign-in or sign-up generates a special token. This token is saved in the browser's cookie as roq-session-token. Any JavaScript framework can utilize this token.

For practical examples, check out add authentication. This detailed documentation explains how to sign in, log out, and sign up for a Next.js project.