fix warning on cookie clear

Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
Stephen Glass
2024-07-28 23:54:30 -04:00
parent 5d8649d775
commit 41b0d71313
3 changed files with 12 additions and 4 deletions
@@ -41,5 +41,5 @@ export type AuthErrorApi = {
* @public
*/
export const authErrorApiRef: ApiRef<AuthErrorApi> = createApiRef({
id: 'core.authError',
id: 'core.auth-error',
});
@@ -22,17 +22,25 @@ const AUTH_ERROR_COOKIE = 'auth-error';
* @public
* Creates a middleware that can be used to get auth errors in redirect flow
*/
export function createCookieAuthErrorMiddleware(authUrl: string) {
export function createCookieAuthErrorMiddleware(
appUrl: string,
authUrl: string,
) {
const router = Router();
router.get('/.backstage/error', async (req, res) => {
const error = req.cookies[AUTH_ERROR_COOKIE];
if (error) {
const { hostname: domain } = new URL(authUrl);
const { hostname: domain, protocol } = new URL(authUrl);
const secure = protocol === 'https:';
const sameSite =
new URL(appUrl).hostname !== domain && secure ? 'none' : 'lax';
res.clearCookie(AUTH_ERROR_COOKIE, {
path: '/api/auth/.backstage/error',
domain,
sameSite,
secure,
});
res.status(200).json(error);
} else {
+1 -1
View File
@@ -179,7 +179,7 @@ export async function createRouter(
throw new NotFoundError(`Unknown auth provider '${provider}'`);
});
router.use(createCookieAuthErrorMiddleware(authUrl));
router.use(createCookieAuthErrorMiddleware(appUrl, authUrl));
return router;
}