DEV Community

Cover image for One-Click Sign In with Next Auth
Gus
Gus

Posted on

One-Click Sign In with Next Auth

In the frontend it's as simple as...

import { signIn } from "next-auth/react";

<button
  onClick={() => signIn("google", { callbackUrl: "/account" })}
>
  Sign in
</Button>
Enter fullscreen mode Exit fullscreen mode

And your api/auth/[...nextauth].ts route stays the same, no extra configuration needed:

const options = {
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_OAUTH_CLIENT_ID,
      clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET,
    }),
  ],
  adapter: PrismaAdapter(prisma),
  secret: process.env.SECRET,
};

const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);

export default authHandler;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)