Skip to content
Discussion options

You must be logged in to vote

Here is the complete solution that worked for me.

import withAuth from "next-auth/middleware";
import { NextResponse } from "next/server";

export { withAuth } from "next-auth/middleware"

// Force-redirect every HTTP request to HTTPS
function forceHTTPS(req) {
    if (process.env.NODE_ENV === 'production' &&
      req.headers?.get('x-forwarded-proto') !== 'https'
      &&
      // This check prevents us from getting trapped in HTTPS localhost if we are
      // testing a production build locally via `next build && next start`; we
      // can use `req.headers.get('host')` to get the true host (e.g.
      // 'example.com'), whereas `req.nextUrl.host` is always
      // 'localhost:3000'
  …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mkbctrl
Comment options

Answer selected by viraj071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants