-
-
Notifications
You must be signed in to change notification settings - Fork 379
[GSK-1087] Avoid multiple requests for license/settings #1262
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
[GSK-1087] Avoid multiple requests for license/settings #1262
Conversation
…slicense-requests
…slicense-requests
kevinmessiaen
left a comment
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.
Looks good to me! Some small code refactoring possible but it's not directly related to the PR
frontend/src/stores/user.ts
Outdated
| let token = this.token; | ||
| if (!token) { | ||
| const localToken = getLocalToken(); | ||
| if (localToken) { | ||
| this.token = localToken; | ||
| token = localToken; |
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 don't think that we really need a token variable since it's always equals to this.token
It seems (need to verify) that we can simplify everything by just
this.token = this.token || getLocalToken()
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.
this doesn't work because getLocalToken() may output null.
that's why there is a double check. let me try to find a better solution to that.
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.
Done! Could you recheck it?
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.
In that case something like this should work: this.token = this.token || getLocalToken() || ''
frontend/src/stores/user.ts
Outdated
| const response = await api.getUserAndAppSettings(); | ||
| this.isLoggedIn = true; | ||
| this.userProfile = response.user; | ||
| let appConfig = response.app; | ||
| mainStore.setAppSettings(appConfig); |
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.
This lines are duplicated with lines 76-80. I think the order of if/else it can be improved to make it more concise
if (!this.isLoggedIn) {
if (mainStore.authAvailable) {
this.token = this.token || getLocalToken();
if (!this.token) {
this.removeLogin();
return;
}
}
const response = await api.getUserAndAppSettings();
this.isLoggedIn = true;
this.userProfile = response.user;
mainStore.setAppSettings(response.app);
}(ideally we should break down to sub function to avoid having too much layers of if)
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 refactored this checkLoggedIn method.
Could you recheck it?
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 saw that you forgot about setting this.token, I fixed that so all good to me
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.
Thanks!!
…slicense-requests
|
Kudos, SonarCloud Quality Gate passed! |








Description
This PR aims to fix a bug which request many times to the backend to /license and /settings endpoint.
Related Issue
GSK-1087 (available on Linear)
Type of Change