Merge pull request #23915 from apc-kamezaki/feature/handle-error-techdocs-cookie

fixed bug the treat as same as no cookie if existing cookie vas invalid.
This commit is contained in:
Patrik Oldsberg
2024-04-02 15:00:29 +02:00
committed by GitHub
2 changed files with 22 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-app-api': patch
---
Fixed a bug where expired cookies would not be refreshed.
@@ -235,14 +235,24 @@ class DefaultHttpAuthService implements HttpAuthService {
return undefined;
}
const existingCredentials = await this.#auth.authenticate(existingCookie, {
allowLimitedAccess: true,
});
if (!this.#auth.isPrincipal(existingCredentials, 'user')) {
return undefined;
}
try {
const existingCredentials = await this.#auth.authenticate(
existingCookie,
{
allowLimitedAccess: true,
},
);
if (!this.#auth.isPrincipal(existingCredentials, 'user')) {
return undefined;
}
return existingCredentials.expiresAt;
return existingCredentials.expiresAt;
} catch (error) {
if (error.name === 'AuthenticationError') {
return undefined;
}
throw error;
}
}
}