Next.js Discord

Discord Forum

next-auth Azure ad validation check

Unanswered
Rock Dove posted this in #help-forum
Open in Discord
Rock DoveOP
In my project after successful authentication I need to if the employee record is existing for that specific email, on the SignIncallback Im calling that API

 async signIn({ user, profile, account }) {
      try {
        const response = await instance.post(
          'auth',
          {},
          {
            headers: {
              'Content-Type': 'application/json',
              Authorization: `Bearer ${user.azureToken}`,
            },
          }
        );

        const data: {
          permissions: string[];
          employeeId: number;
          email: string;
          role: string[];
        } = response.data;

        user.role = data.role || [];
        user.employeeId = data.employeeId || 0;
        user.email = data.email || '';
        user.tenantId = profile?.tid ?? '';
        user.permissions = data.permissions || [];
        user.expiresAt = account?.expires_at ?? 0;
        user.refreshToken = account?.refresh_token ?? '';

        return true;
      } catch (error) {
        console.error(error);
        return false;
      }


what I want to do is if the employee account doesn't exists I want to return that user to sepereate route to get the user credentials.

How can I do that, If I simply return false in previous function it return to error page, I also need that error page to navigae users that are forbidden to acess to my system.

0 Replies