Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback for “Middleware configuration” #423

Open
uilian-comim opened this issue Sep 3, 2024 · 2 comments
Open

Feedback for “Middleware configuration” #423

uilian-comim opened this issue Sep 3, 2024 · 2 comments

Comments

@uilian-comim
Copy link

I'm really liking the library, quite simple to set up, but I'm having a little trouble doing validations and redirects if necessary in the middleware.

I appreciate if someone can send some example code, how a validation should be done and if necessary redirect through the middleware.ts.

@noxify
Copy link

noxify commented Sep 18, 2024

What kind of validation do you mean? Something like "is the user authenticated?"

@wforte4
Copy link

wforte4 commented Oct 8, 2024

Im having the same issue as well

 const isLoggedIn = await fetch(middlewareEndpoint('/auth/is-authenticated'), {
    headers: headers(),
  });

  const hasVerifiedEmail = await fetch(middlewareEndpoint('/auth/is-verified'), {
    headers: headers(),
  });

  // If user is logged in and trying to access a protected route, redirect them to the email verification page
  if (protectedSignupRoutes.includes(request.nextUrl.pathname) && isLoggedIn.status === 200) {
    if (hasVerifiedEmail.status !== 200) {
      return NextResponse.redirect(new URL('/signup/email-verification', request.url));
    }
  }
  // If user is logged in, pass them to their page
  if (isLoggedIn.status === 200) {
    return NextResponse.next();
  }

Trying to do something like this but you can't just wrap the NextResponse.redirect(new URL('/signup/email-verification', request.url)); in the I18nMiddleware function

I see that in v2 branch it looks like they are making support for that but there hasn't been anything since march

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants