feat: support 2fA

This commit is contained in:
kawamataryo 2024-10-19 10:55:10 +09:00
parent 7e79d62a10
commit 1df5e2ba76
5 changed files with 12 additions and 3 deletions

View File

@ -1,7 +1,7 @@
{
"name": "sky-follower-bridge",
"displayName": "Sky Follower Bridge",
"version": "0.9.4",
"version": "0.9.5",
"description": "Instantly find and follow the same users from your Twitter follows on Bluesky.",
"author": "kawamataryou",
"scripts": {

View File

@ -46,6 +46,7 @@ const App = () => {
body: {
identifier: string;
password: string;
authFactorToken?: string;
};
},
_sender: chrome.runtime.MessageSender,
@ -56,6 +57,9 @@ const App = () => {
identifier: message.body.identifier,
password: message.body.password,
messageName: message.name,
...(message.body.authFactorToken && {
authFactorToken: message.body.authFactorToken,
}),
})
.then(() => {
sendResponse({ hasError: false });

View File

@ -4,6 +4,7 @@ import { sendToBackground } from "@plasmohq/messaging";
export type BskyLoginParams = {
identifier: string;
password: string;
authFactorToken?: string;
};
export class BskyServiceWorkerClient {
@ -14,6 +15,7 @@ export class BskyServiceWorkerClient {
public static async createAgent({
identifier,
password,
authFactorToken,
}: BskyLoginParams): Promise<BskyServiceWorkerClient> {
const client = new BskyServiceWorkerClient();
const { session, error } = await sendToBackground({
@ -21,6 +23,7 @@ export class BskyServiceWorkerClient {
body: {
identifier,
password,
...(authFactorToken && { authFactorToken: authFactorToken }),
},
});
if (error) throw new Error(error.message);

View File

@ -196,10 +196,12 @@ export const useRetrieveBskyUsers = () => {
identifier,
password,
messageName,
authFactorToken,
}: {
identifier: string;
password: string;
messageName: (typeof MESSAGE_NAMES)[keyof typeof MESSAGE_NAMES];
authFactorToken?: string;
}) => {
setRetrievalParams({
identifier,
@ -210,6 +212,7 @@ export const useRetrieveBskyUsers = () => {
bskyClient.current = await BskyServiceWorkerClient.createAgent({
identifier,
password,
...(authFactorToken && { authFactorToken: authFactorToken }),
});
setActionMode(MESSAGE_NAME_TO_ACTION_MODE_MAP[messageName]);

View File

@ -109,7 +109,7 @@ function IndexPopup() {
},
});
if (res.hasError) {
if (res.message === AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE) {
if (res.message.includes(AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE)) {
setIsShowAuthFactorTokenInput(true);
} else {
setErrorMessage(res.message);
@ -130,7 +130,6 @@ function IndexPopup() {
setErrorMessage(
"Error: Something went wrong. Please reload the web page and try again.",
);
console.error(e);
}
} finally {
setIsLoading(false);