1

I have a condition where certain pages can be accessed according to their role in database

I have followed the tutorial on the Authjs site, and it seems like there is a lack of information, because there is an error in my coding

I use mongoose (mongodb), nextjs, and Google provider (OAuth)

My auth config:

import GitHub from "next-auth/providers/github"
import type { NextAuthConfig } from "next-auth"
import Google from "next-auth/providers/google"
import Credentials from "next-auth/providers/credentials"

export default {
    providers: [
        Google({
            profile(profile) {
                return { role: profile.role ?? "user", ...}
            }
        }),
    ]
} satisfies NextAuthConfig

Callbacks:

  callbacks: {
        async session({ session, token, user }) {
            // `session.user.address` is now a valid property, and will be type-checked
            // in places like `useSession().data.user` or `auth().user`
            return {
                ...session,
                user: {
                    ...session.user,
                },
            }
        },
    },

The Error:

... Expression expected.

Middleware:

// export { auth as middleware } from "@/auth";

import NextAuth from "next-auth"
import authConfig from "./libs/auth-js/auth.config"

export const { auth: middleware } = NextAuth(authConfig)
1
  • If you're trying to spread in role: return { ...profile, role: profile.role ?? "user"} Commented Jan 3 at 14:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.