Skip to content

Commit

Permalink
fix: bug in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamataryo committed Jan 12, 2025
1 parent f657a0d commit 7f066a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/background/messages/getMyProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { session } = req.body;
try {
const client = await BskyClient.createAgentFromSession(session);
const profile = await client.getMyProfile();
const result = await client.getMyProfile();
res.send({
result: {
pdsUrl: profile.pdsUrl,
did: profile.did,
handle: profile.handle,
displayName: profile.displayName,
avatar: profile.avatar,
},
result: JSON.stringify(await client.getMyProfile()),
});
} catch (e) {
res.send({
Expand Down
16 changes: 14 additions & 2 deletions src/lib/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sendToBackground } from "@plasmohq/messaging";
import destr from "destr";
import { useCallback, useEffect, useState } from "react";
import {
getChromeStorage,
Expand Down Expand Up @@ -123,8 +124,12 @@ export const useAuth = () => {
if (error) {
return false;
}
setDisplayName(result.displayName);
setAvatar(result.avatar);
const parsedResult = destr<{
displayName: string;
avatar: string;
}>(result);
setDisplayName(parsedResult.displayName);
setAvatar(parsedResult.avatar);
return true;
}, []);

Expand Down Expand Up @@ -155,6 +160,13 @@ export const useAuth = () => {
});
if (error) {
if (error.message.includes(AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE)) {
if (isShowAuthFactorTokenInput) {
setErrorMessage(
chrome.i18n.getMessage("error_enter_auth_factor_token"),
DOCUMENT_LINK.LOGIN_ERROR,
);
return;
}
setIsShowAuthFactorTokenInput(true);
await saveShowAuthFactorTokenInputToStorage(true);
} else if (error.message.includes(RATE_LIMIT_ERROR_MESSAGE)) {
Expand Down

0 comments on commit 7f066a4

Please sign in to comment.