Skip to content

Commit

Permalink
feat: Add server check in middleware (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser authored Jan 22, 2024
1 parent 0eea47a commit cf32ea7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof signIn>[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<typeof navigateToAuthPages>
Expand Down

0 comments on commit cf32ea7

Please sign in to comment.