DEV Community

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

Posted on

5 3

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay