Skip to content
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

Merged
merged 8 commits into from
Mar 7, 2024
Merged

Conversation

kahlstrm
Copy link

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

@kahlstrm kahlstrm self-assigned this May 25, 2023
@kahlstrm kahlstrm added this to the 2.1.0 milestone May 25, 2023
@kahlstrm kahlstrm added the 🌠 feature New feature - accepted for development label May 25, 2023
@kahlstrm kahlstrm force-pushed the feature/89-renew-session-token branch from 16e12ef to f8a563b Compare May 25, 2023 18:55
packages/ilmomasiina-components/src/api.ts Outdated Show resolved Hide resolved
packages/ilmomasiina-frontend/src/api.ts Outdated Show resolved Hide resolved
packages/ilmomasiina-frontend/src/modules/auth/actions.ts Outdated Show resolved Hide resolved
packages/ilmomasiina-models/src/schema/login/index.ts Outdated Show resolved Hide resolved
@kahlstrm kahlstrm force-pushed the feature/89-renew-session-token branch from 4790c73 to 290edb8 Compare May 27, 2023 11:53
Copy link
Member

@PurkkaKoodari PurkkaKoodari left a 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.

Comment on lines 49 to 51
if (!sessionResponse) {
throw Error('Bad response');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return response.status === 204 ? null : response.json() as T;
return (response.status === 204 ? null : response.json()) as T;

Comment on lines 329 to 328
// an API endpoint for session token renewal as variant of adminLoginSchema

server.post(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// an API endpoint for session token renewal as variant of adminLoginSchema
server.post(
server.post(

@PurkkaKoodari PurkkaKoodari force-pushed the feature/89-renew-session-token branch from 4347952 to ba4ff29 Compare March 7, 2024 17:10
@PurkkaKoodari PurkkaKoodari merged commit cc310ba into dev Mar 7, 2024
1 check passed
@PurkkaKoodari PurkkaKoodari deleted the feature/89-renew-session-token branch March 7, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌠 feature New feature - accepted for development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto renew active session
2 participants