Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/stores/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const useUserStore = defineStore({
if (token) {
return token
}
const local_token = localStorage.getItem(`${token}-accessToken`)
const local_token = localStorage.getItem(`${this.userAccessToken}-accessToken`)
if (local_token) {
return local_token
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code snippet provided has a few issues that need to be addressed:

  1. Incorrect Use of this: The line const local_token = localStorage.getItem(${this.userAccessToken}-accessToken) is using the keyword this, which refers to the current object in the context where it's used. If this is expected to refer to an instance property like userAccessToken, ensure that userAccessToken is properly defined and accessible within the correct scope.

    const userAccessToken = 'your-access-token-value'; // Example value, replace with actual logic
    
    const useUserStore = defineStore({
      state() {
        return {
          userAccessToken: userAccessToken // Ensure this is set up correctly
        };
      },
      getters: {},
      actions: {}
    });
  2. Accessing State Directly: The line return local_token; assumes that local_token contains JWT data. Make sure that you're handling this token appropriately, such as parsing it before returning it or converting it into JSON format depending on your requirements.

  3. Variable Name Consistency: You've changed one occurrence of ${token} to ${this.userAccessToken}, but remember to keep consistency across your application.

  4. Error Handling: It would be beneficial to add error handling around getting tokens from either storage to manage cases where no token is found or there is an issue retrieving the data.

Overall, ensure proper access and initialization of variables, handle edge cases, and maintain clean code practices for better readability and reliability.

Expand Down