Next.js Discord

Discord Forum

Can't sign in with notion

Unanswered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
I use new authjs.dev v5 and I can't login in to my app with notion it shows me this login screen but then redirects back to homepage but my session still acts as if i was not logged in

14 Replies

Forest bachac
send code
RhinelanderOP
import prisma from "@/prisma/db";
import { PrismaAdapter } from "@auth/prisma-adapter";
import NextAuth from "next-auth";
import Notion from "next-auth/providers/notion";

export const { handlers, signIn, signOut, auth } = NextAuth({
  trustHost: true,
  adapter: PrismaAdapter(prisma),
  providers: [Notion],
});
auth.ts
import { Button } from "@/components/ui/button";
import Link from "next/link";

const SignIn = () => {
  return (
    <div className="h-[500px] w-full max-w-[600px] rounded-md border bg-muted">
      <Link href={process.env.AUTH_URL!}>
        <Button variant="outline" type="submit">
          Signin with Notion
        </Button>
      </Link>
    </div>
  );
};

export default SignIn;
my signin screen
Forest bachac
So what isn't working
Where are you checking for auth state
RhinelanderOP
  <form
      action={async () => {
        "use server"
        await signIn("notion")
      }}
    >
      <button type="submit">Signin with Notion</button>
   </form>
This redirect me to /undefined
I have this code
import { auth } from "@/auth";
import { cache } from "react";

export default cache(auth);
So i have this code that caches my auth
so on every website i just check const session = await getSession() and get user from that so const user = session.user it worked for google
But as soon as i tried notion did not work
I get redirected back but i am not logged in i just get this code in url that i can use for backend
but on the guide it says that i should be authenticated and get the code