mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-09-13 23:43:31 -06:00
✨ support 2FA auth
This commit is contained in:
@@ -1,24 +1,35 @@
|
||||
import type { PlasmoMessaging } from "@plasmohq/messaging";
|
||||
import { BskyClient } from "../../lib/bskyClient";
|
||||
import { AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE } from "~lib/constants";
|
||||
import { ComAtprotoServerCreateSession } from "@atproto/api";
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
|
||||
const { identifier, password } = req.body;
|
||||
const { identifier, password, authFactorToken } = req.body;
|
||||
|
||||
try {
|
||||
const agent = await BskyClient.createAgent({
|
||||
identifier,
|
||||
password,
|
||||
...(authFactorToken && { authFactorToken: authFactorToken }),
|
||||
});
|
||||
|
||||
res.send({
|
||||
session: agent.session,
|
||||
});
|
||||
} catch (e) {
|
||||
res.send({
|
||||
error: {
|
||||
message: e.message,
|
||||
},
|
||||
});
|
||||
if (e instanceof ComAtprotoServerCreateSession.AuthFactorTokenRequiredError) {
|
||||
res.send({
|
||||
error: {
|
||||
message: AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
error: {
|
||||
message: e.message,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user