Skip to content

Commit

Permalink
fix: add try catch for extenstion msg
Browse files Browse the repository at this point in the history
  • Loading branch information
var-code-5 committed Dec 16, 2024
1 parent cafb7a5 commit 5c0f8cc
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions ao3 webpages/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,26 @@ export default function Login() {
// Store tokens in localStorage
localStorage.setItem('accessToken', data.accessToken);
localStorage.setItem('refreshToken', data.refreshToken);

console.log('setmsg');
// Send both tokens to the Chrome extension
chrome.runtime.sendMessage("nnmmeljlhmhpnfphcpifdahblfmhlilm",
{ action: "storeTokens", accessToken: data.accessToken, refreshToken: data.refreshToken },
function(response) {
if (chrome.runtime.lastError) {
console.error('Error sending message:', chrome.runtime.lastError);
} else {
console.log('Tokens sent to extension:', response);
}
});


try{
chrome.runtime.sendMessage("nnmmeljlhmhpnfphcpifdahblfmhlilm",
{ action: "storeTokens", accessToken: data.accessToken, refreshToken: data.refreshToken },
function(response) {
if (chrome.runtime.lastError) {
console.error('Error sending message:', chrome.runtime.lastError);
} else {
console.log('Tokens sent to extension:', response);
}
});
} catch (e) {
console.error('Error sending tokens to Chrome extension:', e);
setMessage('An error occurred while sending tokens to the Chrome extension.');
setMessageType('error');
}
setMessage('Login successful');
setMessageType('success');

setTimeout(() => {
window.location.href = '/dashboard';
}, 1500);
Expand Down

0 comments on commit 5c0f8cc

Please sign in to comment.