Skip to content

Commit

Permalink
Redirect on token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
NebraskaCoder committed Jun 28, 2024
1 parent a487322 commit 16c3b44
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const updateCookie = (
res: NextResponse
) => {
if (sessionToken) {
res = NextResponse.redirect(req.url, { headers: req.headers });
// Set the session token in the request and response cookies for a valid session
req.cookies.set(sessionCookieName, sessionToken);
res.cookies.set(sessionCookieName, sessionToken, {
Expand Down Expand Up @@ -141,7 +142,9 @@ const authMiddleware = withAuth(
return NextResponse.redirect(new URL(signinSubUrl, req.url));
}

const reponseNext = intlMiddleware(req);
const isAPIPath = req.nextUrl.pathname.startsWith("/api");

const reponseNext = isAPIPath ? NextResponse.next() : intlMiddleware(req);

if (shouldUpdateToken(token)) {
try {
Expand Down Expand Up @@ -186,5 +189,6 @@ export default async function middleware(req: NextRequest) {

export const config = {
// Skip all paths that should not be internationalized
matcher: ["/((?!api|_next|.*\\..*).*)"],
// matcher: ["/((?!api|_next|.*\\..*).*)"],
matcher: ["/((?!_next|.*\\..*).*)"],
};

0 comments on commit 16c3b44

Please sign in to comment.