Recently, I've been working on implementing Google authentication in my Next.js and Strapi application.
However, every time I attempt to do so, I encounter the following error:
Error: This action with HTTP GET is not supported by NextAuth.js
.
The issue seems to be rooted in the code found in 'api/auth/[...nextauth].jsx'
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
const options = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
secret: process?.env?.NEXT_PUBLIC_SECRET,
callbacks: {
async session({ session, token }) {
session.jwt = token.jwt;
session.id = token.id;
return session;
},
async jwt({ token, user, account }) {
if (user) {
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account.access_token}`
);
const data = await response.json();
token.jwt = data.jwt;
token.id = data.user.id;
}
return token;
},
},
};
const Auth = (req, res) => NextAuth(req, res, options);
export default Auth;
I have ensured that the redirect URIs specified in the Google console are:
https://frontend.com/api/auth/callback/google
https://backend.com/api/auth/callback/google
Additionally, the redirect URI in Strapi has been set as:
https://frontend.com/api/auth/callback/google