-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/89 renew session token #104
Conversation
16e12ef
to
f8a563b
Compare
packages/ilmomasiina-frontend/src/modules/adminEvents/actions.ts
Outdated
Show resolved
Hide resolved
4790c73
to
290edb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for this instead. It makes no sense for every caller to need to check for 204 responses separately, when the API typings should already indicate when a 204 might be expected.
if (!sessionResponse) { | ||
throw Error('Bad response'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!sessionResponse) { | |
throw Error('Bad response'); | |
} |
@@ -66,5 +62,5 @@ export default async function apiFetch(uri: string, { | |||
if (!response.ok) { | |||
throw await ApiError.fromResponse(response); | |||
} | |||
return response.status === 204 ? null : response.json(); | |||
return response.status === 204 ? null : response.json() as T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return response.status === 204 ? null : response.json() as T; | |
return (response.status === 204 ? null : response.json()) as T; |
// an API endpoint for session token renewal as variant of adminLoginSchema | ||
|
||
server.post( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// an API endpoint for session token renewal as variant of adminLoginSchema | |
server.post( | |
server.post( |
4347952
to
ba4ff29
Compare
Refactored auth typing in frontend and had it refresh the token using the already existing but not yet mapped to a route endpoint. Functionality is the following:
If the admin has logged and tries to reach an admin endpoint, the code checks the expiry time of the access token. If access token is expiring in less than 4 minutes, request a new access token from the endpoint.
Closes #89