From 3bb7e1a850e81c133dead7f84f27a2707941e388 Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 6 Dec 2022 23:38:28 +0300 Subject: [PATCH] fix save uri to query and get it --- apps/api/src/auth/auth.controller.ts | 9 +-------- example/nginx.conf | 8 +++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/api/src/auth/auth.controller.ts b/apps/api/src/auth/auth.controller.ts index c3f3bd0..b28f97b 100644 --- a/apps/api/src/auth/auth.controller.ts +++ b/apps/api/src/auth/auth.controller.ts @@ -29,14 +29,7 @@ export class AuthController { private getTargetUri(req) { const refererURL = new URL(req?.headers?.referer); - const uri = refererURL.searchParams.get('uri'); - if (uri) return uri; - - if (refererURL.pathname.includes('/login')) { - return refererURL.href.split('/login')[1] || '/'; - } - - return '/'; + return refererURL.searchParams.get('uri') || '/'; } private getInvalidPasswordUrl(targetUri: string) { diff --git a/example/nginx.conf b/example/nginx.conf index 19e12dd..81e2488 100644 --- a/example/nginx.conf +++ b/example/nginx.conf @@ -20,7 +20,13 @@ http { listen 80; include /etc/nginx/mime.types; - error_page 401 /login; + error_page 401 @error401; + + location @error401 { + add_header Cache-Control 'no-store, no-cache'; + rewrite ^ /login?uri=$request_uri permanent; + } + location = /auth { internal;