Authentication
Authentication Options

Authentication options

Introduction

To get more fine-grained control over the login and registration experience, or add your own business logic, you can supply options to the RoqAuth handlers. We provide hooks that allow you to execute code on various events during registration, login, and logout.

Authentication hooks

The following hooks can (optionally) be passed in to the RoqAuth handler

onLoginSuccess

Create a new file: pages/api/[...roqAuth].ts with this content. Next.js will automatically detect and import the handler.

import { RoqAuth } from "@roq/nextjs";
import { User } from "your/server/code";
 
export default RoqAuth({
  hooks: {
    // This hook is optional - and can be used to persist user information,
    // or in the case below - update the last seen for the user on your database
    onLoginSuccess: async ({ session, user }) => {
      User.updateLastSeen(user.id, new Date());
    },
  },
});

onRegisterSuccess

import { RoqAuth } from "@roq/nextjs";
import { Restaurant } from "your/server/code";
 
export default RoqAuth({
  hooks: {
    //Perform some business logic on your server & db
    onRegisterSuccess: async ({ session, user }) => {
      Restaurant.addManager(user.tenantId, user.id);
    },
  },
});