Only show Credentials provider in the Sign in page #3133
-
|
I have two providers: CredentialsProvider (for users) and GoogleProvider (for admins). I want to make a sign in button, which, when clicked, will only show the Credentials fields, and not the Google OAuth button. I have tried to use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Not by default, but I believe this should work: // /api/auth/[...nextauth].js
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import GoogleProvider from "next-auth/providers/google"
export default async function auth(req, res) {
const providers = [
CredentialsProvider({
// ...
}),
GoogleProvider({
// ...
})
]
// Based on https://next-auth.js.org/getting-started/rest-api#get-apiauthsignin
const isDefaultSigninPage = req.method === "GET" && req.query.nextauth.includes("signin")
if (isDefaultSigninPage) providers.pop()
return await NextAuth(req, res, {
providers,
// rest of your config ...
})
}So whenever the default sign-in page gets rendered, you just exclude the |
Beta Was this translation helpful? Give feedback.
-
|
I just referred to this discussion in a new section in the docs FYI 🙂 nextauthjs/docs#109 |
Beta Was this translation helpful? Give feedback.
Not by default, but I believe this should work: