From ec59602fdb960a0f21119b27c61a079b9f3341c7 Mon Sep 17 00:00:00 2001 From: Zoey Kaiser Date: Mon, 22 Jan 2024 10:24:48 +0100 Subject: [PATCH] added server check in middleware --- src/runtime/middleware/auth.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/middleware/auth.ts b/src/runtime/middleware/auth.ts index d23d48b8..c2f3badb 100644 --- a/src/runtime/middleware/auth.ts +++ b/src/runtime/middleware/auth.ts @@ -85,6 +85,10 @@ export default defineNuxtRouteMiddleware((to) => { } if (authConfig.provider.type === 'authjs') { + // If the middleware runs on a pre-render of the route, do not call signIn, as this is a client method + if (process.server) { + return + } const signInOptions: Parameters[1] = { error: 'SessionRequired', callbackUrl: determineCallbackUrl(authConfig, () => to.path) } // @ts-ignore This is valid for a backend-type of `authjs`, where sign-in accepts a provider as a first argument return signIn(undefined, signInOptions) as ReturnType