Skip to content

Commit cf32ea7

Browse files
authored
feat: Add server check in middleware (#644)
1 parent 0eea47a commit cf32ea7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/runtime/middleware/auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export default defineNuxtRouteMiddleware((to) => {
8585
}
8686

8787
if (authConfig.provider.type === 'authjs') {
88+
// If the middleware runs on a pre-render of the route, do not call signIn, as this is a client method
89+
if (process.server) {
90+
return
91+
}
8892
const signInOptions: Parameters<typeof signIn>[1] = { error: 'SessionRequired', callbackUrl: determineCallbackUrl(authConfig, () => to.path) }
8993
// @ts-ignore This is valid for a backend-type of `authjs`, where sign-in accepts a provider as a first argument
9094
return signIn(undefined, signInOptions) as ReturnType<typeof navigateToAuthPages>

0 commit comments

Comments
 (0)