Reputation: 23
I'm using next-auth (v5). I have set up OAuth with a Github account, and it works fine. Next, I want to implement "login is possible only with my Github account".
In this case, I think I should define signIn
in callbacks
of next-auth,
and return true
only if the account used for sign-in matches my account.
As a test, I set signIn
to always return false
.
However, when I log in with a Github account, the login is successful.
Am I misunderstanding something?
By the way, even if the authentication operation is performed,
console.log
is not executed, so it seems that signIn
itself is not activated.
import NextAuth from "next-auth";
import { authConfig } from "./config";
import { db } from "~/server/db";
import { PrismaAdapter } from "@auth/prisma-adapter";
export const { auth, handlers, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(db),
session: { strategy: "jwt" },
callbacks: {
signIn: async ({ user }) => {
console.log("Forcibly fail authentication");
return false;
},
session: async ({ session, token }) => ({
...session,
user: {
...session.user,
id: token.sub,
},
}),
},
pages: {
signIn: "/signin",
},
...authConfig,
});
Upvotes: 0
Views: 36
Reputation: 23
Self resolved. The callbacks signIn does not control sign-in, it is a callback that is executed when sign-in is performed. It also appears that it is not something that can be used with OAuth.
Upvotes: 0