Next.js Discord

Discord Forum

Is there any way I can acccess the callback url in the signin callback in nextauth?

Unanswered
Leonberger posted this in #help-forum
Open in Discord
LeonbergerOP
Hi, I am trying to implement a role based authentication where I have two different sign in/ sign up pages for two different roles. for student role I want to allow signups only via admin ie admin can create student accounts. if the student doesnt exist in db I want deny access. How do I do this my current signin callback looks like this
async signIn({ user }) {
      await connectDB(); // Ensure DB is connected

      // Check if the user already exists in MongoDB
      const existingUser = await User.findOne({ email: user.email });
      if (!existingUser) {
        // Create a new user if they don't exist
        if (!user.email) {
          return false;
        }
        if (!user.name) {
          await User.create({
            email: user.email,
            name: user.name ?? "NA",
            image: user.image,
            // Add any other fields you need
          });
        } else {
          await User.create({
            email: user.email,
            name: user.name,
            image: user.image,
            // Add any other fields you need
          });
        }
      }
      return true; // Proceed with the sign-in
    },
 


I was thinking If somehow I could access the callback url in signin callback I could deny access if user is not in the db and callback url is /student/signin

0 Replies