NextAuth Google login directly from the homepage without redirecting to the default sign-in page or custom sign-in page in NextJs

Viewed 1078

I am using NextAuth for my NextJS application. When using NextAuth, it redirects to its own sign-in page when signing in or we can add our own custom sign-in page but what I want to do is sign-in without redirecting it to the sign-in page directly from the homepage login button. Any ideas on how can I achieve that?

1 Answers

I think you can do something like this ...

import { signIn } from "next-auth/client"

export default () => (
  <button onClick={() => signIn("google")}>Sign in with Google</button>
)

So you can use pass any OAuth provider that are compatible with NextAuth to signIn and it will use that provider by default instead of redirecting you to a page.

Thanks

Related