#pages/api/auth I'm currently in the process of developing an authentication system using Nextauth in Next Js. I encountered an issue with authenticating using credentials while following a tutorial on YouTube.I've double-checked the syntax multiple times, but I can't seem to pinpoint the problem. Here's the link to the video I was watching: https://www.youtube.com/watch?v=EFucgPdjeNg&t=436s Unfortunately, I'm stuck with this error. Any assistance would be greatly appreciated!
import NextAuth,{ NextAuthOptions } from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'
import GithubProvider from 'next-auth/providers/github'
import CredentialsProvider from "next-auth/providers/credentials";
// import Providers from 'next-auth/providers'
// import sessionProvider from 'next-auth'
// const client_Id="207449855842-gv24ltosjj4ahf1r7lelc4jiii5qsqe8.apps.googleusercontent.com"
// const client_secret="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"
export default NextAuth({
providers: [
GoogleProvider({
client_Id:process.env.GOOGLE_ID,
clientSecret:process.env.GOOGLE_SECRET,
}),
GithubProvider({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
}),
CredentialsProvider({
type: "Credentials",
credentials: {
// email: { label: "Email address", type: "text" },
// password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const { email, password } = credentials as {
email: string;
password: string;
};
if (email !== "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d2d7d0d6f8dfd5d9d1d496dbd7d5">[email protected]</a>" || password !== "1234") {
throw new Error("invalid credentials");
}
return {
id: "1234",
name: "John Doe",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2989d9a9cb2959f939b9edc919d9f">[email protected]</a>",
role: "admin",
};
}
}),
callbacks: {
jwt(params) {
// update token
if (params.user?.role) {
params.token.role = params.user.role;
}
// return final_token
return params.token;
},
},
session: {
strategy: "jwt",
},
pages: {
signIn: "/login",
},
],
secret:"[6j2Ld_PiUl3etQENg0swsJnuMaAJ]",
debug:true
})
ERROR
Error:
x Expected a semicolon
,-[C:\Users\acer\Desktop\next\fundraiser\pages\api\auth\[...nextauth].js:26:1]
26 | },
27 | async authorize(credentials, req) {
28 |
29 | const { email, password } = credentials as {
: ^^
30 | email: string;
31 | password: string;
31 | };
`----
x Expected ',', got ';'
,-[C:\Users\acer\Desktop\next\fundraiser\pages\api\auth\[...nextauth].js:29:1]
29 | const { email, password } = credentials as {
30 | email: string;
31 | password: string;
32 | };
: ^
33 | if (email !== "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e3898c8b8da3848e828a8fcd808c8e">[email protected]</a>" || password !== "1234") {
34 | throw new Error("invalid credentials");
34 | }
`----
Caused by:
Syntax Error