-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: Historical user conversation data has been cleared #2843
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,8 +97,8 @@ const useApplicationStore = defineStore({ | |
applicationApi | ||
.postAppAuthentication(token, loading, authentication_value) | ||
.then((res) => { | ||
localStorage.setItem(`${token}accessToken`, res.data) | ||
sessionStorage.setItem(`${token}accessToken`, res.data) | ||
localStorage.setItem(`${token}-accessToken`, res.data) | ||
sessionStorage.setItem(`${token}-accessToken`, res.data) | ||
resolve(res) | ||
}) | ||
.catch((error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet has a couple of small optimizations you might consider:
By implementing these changes, the code becomes cleaner, more robust, and adheres better to best practices for both syntax and functionality. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,11 +61,11 @@ const useUserStore = defineStore({ | |
return this.userType === 1 ? localStorage.getItem('token') : this.getAccessToken() | ||
}, | ||
getAccessToken() { | ||
const token = sessionStorage.getItem(`${this.userAccessToken}accessToken`) | ||
const token = sessionStorage.getItem(`${this.userAccessToken}-accessToken`) | ||
if (token) { | ||
return token | ||
} | ||
const local_token = localStorage.getItem(`${token}accessToken`) | ||
const local_token = localStorage.getItem(`${token}-accessToken`) | ||
if (local_token) { | ||
return local_token | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet has a small issue that needs to be addressed: const useUserStore = defineStore({
state: () => ({
userType: null,
userAccessToken: '',
}),
actions: {
getTokenFromStorage(type) {
let token;
if (type === 'session') {
token = sessionStorage.getItem(`${this.userAccessToken}-accessToken`);
} else { // Assuming 'local' means using localStorage
token = localStorage.getItem(`${this.userAccessToken}-accessToken`);
}
return token || '';
},
getAccessToken(token_type) {
const storedToken = this.getTokenFromStorage(token_type);
const isSessionToken = token_type === 'session';
const access_token = isSessionToken ? storedToken : this.getAccessToken();
return access_token;
}
}
}); Explanation of the Improvement:
This change improves readability and maintainability while maintaining the same functionality. |
||
|
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.
The provided code snippet has one primary issue:
Type Inconsistency in
validate
Function: The original code specifies thatvalidate
returnsPromise<boolean | string>
, which means it can either resolve to a Boolean value or a String indicating an error.Updated Type for
validate
:This change allows
validate
to return any type of object or data, which is not appropriate according to the previous definition. You should ideally specifystring
as the return type if you plan on returning errors, or otherwise define a common type for both success outcomes and errors.To maintain correctness, here is how you could update the function declaration:
This update maintains consistency with the expected behavior specified in the initial
withDefaults
setup when callingvalidate()
.