swarooppatilx / scruter

Scruter is a local classifieds and community site designed to bring people together for buying, selling, and exchanging goods and services.
https://scruter.vercel.app
GNU General Public License v3.0
28 stars 135 forks source link

Admin: schema , admin Role Type-in nextauth , loginPage , auth.ts modification #528

Closed ShivanshPlays closed 1 week ago

ShivanshPlays commented 1 week ago

Add Admin Role and Admin Login Functionality

Description

This PR introduces the Admin Role for the application, adds functionality for Admin Login, and modifies the authentication logic to handle the admin role type. The following changes have been made:

Changes:

  1. Admin Schema in Prisma:

    • A new Admin model has been added to the Prisma schema.
    • The Admin model includes:
      • id: Unique identifier.
      • email: Admin email for login.
      • password: Admin's encrypted password.
      • role: Admin role, which could be used for different permissions.
  2. NextAuth Role Configuration:

    • Modified the NextAuth configuration to include an admin role type.
    • The role of the user is now part of the JWT token and is checked during session creation.
    • Admins are given special access based on their role.
  3. LoginPage:

    • Created the admin LoginPage to allow admin users to sign in using their credentials.
    • will be made functional in subsequent PRs
  4. auth.ts Modification:

    • Updated auth.ts to handle the admin role logic:
      • Ensures that users with the admin role can authenticate and be authorized to access admin routes.
      • Proper error handling has been added for failed login attempts.
      • The JWT and session callbacks have been updated to include the role of the user for authorization checks.

PR1 #518

vercel[bot] commented 1 week ago

@ShivanshPlays is attempting to deploy a commit to the Piyush's projects Team on Vercel.

A member of the Team first needs to authorize it.