diff --git a/auth.ts b/auth.ts index f569573..2d11832 100644 --- a/auth.ts +++ b/auth.ts @@ -1,4 +1,4 @@ -import NextAuth, { type DefaultSession } from "next-auth"; +import NextAuth from "next-auth"; import Authentik from "next-auth/providers/authentik"; import { PrismaAdapter } from "@auth/prisma-adapter" import { PrismaClient } from "@prisma/client" @@ -36,6 +36,10 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ where: { userId: user.id, provider: "authentik" }, }) + if (!authentikAccount.expires_at || !authentikAccount.refresh_token) { + throw "Expiry time or refresh token not set"; + } + if (authentikAccount.expires_at * 1000 < Date.now()) { console.info("refreshing token"); try { @@ -73,7 +77,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ session.error = "RefreshAccessTokenError" } } - return session + return { ...session, access_token: authentikAccount.access_token } } } }); diff --git a/src/app/page.tsx b/src/app/page.tsx index 9b68f12..8bcf899 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,28 +1,27 @@ -import { signIn,signOut, auth } from "auth" +import { signIn, signOut, auth } from "auth" export default async function Home() { -let session = await auth(); + let session = await auth(); -console.log(session?.access_token) - return ( - <> -

Hello {session?.user?.name}!

-
{ - "use server" - await signIn("authentik") - }} - > - -
-
{ - "use server" - await signOut() - }} - > - -
- - ); + return ( + <> +

Hello {session?.user?.name}!

+
{ + "use server" + await signIn("authentik") + }} + > + +
+
{ + "use server" + await signOut() + }} + > + +
+ + ); }