-
Notifications
You must be signed in to change notification settings - Fork 1
Handle auth errors, make sure to only open auth tab once #157
Conversation
WalkthroughWalkthroughThe changes involve enhancements to the background script in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant BackgroundScript
participant ChromeStorage
participant TabManager
User->>BackgroundScript: Request authentication
BackgroundScript->>ChromeStorage: Get auth data
alt Auth data exists
ChromeStorage-->>BackgroundScript: Return auth data
BackgroundScript-->>User: Provide access
else Auth data missing
BackgroundScript->>TabManager: Show auth tab
TabManager-->>BackgroundScript: Open new tab
BackgroundScript-->>User: Prompt for login
end
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/mocksi-lite-next/src/pages/background/index.ts (3 hunks)
Additional comments not posted (2)
apps/mocksi-lite-next/src/pages/background/index.ts (2)
89-101
: LGTM! The changes to handle authentication errors are well-structured.The modifications to the
onMessageExternal
listener effectively handle authentication errors by usingclearAuth
andshowAuthTab
.
27-46
: Verify the environment variableVITE_NEST_APP
.Ensure that
import.meta.env.VITE_NEST_APP
is defined and correctly set in the environment variables.Run the following script to verify the presence of the environment variable in the codebase:
Verification successful
Environment variable
VITE_NEST_APP
is correctly defined.The variable is set in both
.env.production
and.env.development
files, ensuring it is available for different environments.
apps/mocksi-lite-next/.env.production
:VITE_NEST_APP=https://nest-auth-ts-merge.onrender.com
apps/mocksi-lite-next/.env.development
:VITE_NEST_APP=http://localhost:3030
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `VITE_NEST_APP` in the codebase. # Test: Search for the environment variable usage. Expect: At least one occurrence. rg --type js --type ts 'import\.meta\.env\.VITE_NEST_APP'Length of output: 528
Script:
#!/bin/bash # Description: Check for the definition of `VITE_NEST_APP` in environment configuration files. # Test: Search for the definition of `VITE_NEST_APP` in common environment files. rg 'VITE_NEST_APP' --glob '**/.env*'Length of output: 203
const clearAuth = async (): Promise<void> => { | ||
try { | ||
const storageAuth = await chrome.storage.local.get(MOCKSI_AUTH); | ||
storageAuth[MOCKSI_AUTH] = null; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; |
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.
Ensure authentication data is cleared from storage.
The function sets the authentication data to null
but does not save the changes back to Chrome's local storage.
Apply this diff to fix the function:
const clearAuth = async (): Promise<void> => {
try {
const storageAuth = await chrome.storage.local.get(MOCKSI_AUTH);
storageAuth[MOCKSI_AUTH] = null;
+ await chrome.storage.local.set({ [MOCKSI_AUTH]: null });
} catch (err) {
console.error(err);
}
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const clearAuth = async (): Promise<void> => { | |
try { | |
const storageAuth = await chrome.storage.local.get(MOCKSI_AUTH); | |
storageAuth[MOCKSI_AUTH] = null; | |
} catch (err) { | |
console.error(err); | |
} | |
}; | |
const clearAuth = async (): Promise<void> => { | |
try { | |
const storageAuth = await chrome.storage.local.get(MOCKSI_AUTH); | |
storageAuth[MOCKSI_AUTH] = null; | |
await chrome.storage.local.set({ [MOCKSI_AUTH]: null }); | |
} catch (err) { | |
console.error(err); | |
} | |
}; |
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.
LGTM
Handle auth errors by showing auth tab
Check that we don't open the auth tab multiple times
Summary by CodeRabbit
New Features
clearAuth
function to clear stored authentication data.showAuthTab
function to manage tab creation and display based on authentication status.Improvements