fix: handle a few more cases
This commit is contained in:
@@ -113,6 +113,7 @@ const ApiContext = React.createContext<ApiContext>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function createPersistSessionHandler(
|
function createPersistSessionHandler(
|
||||||
|
agent: BskyAgent,
|
||||||
account: SessionAccount,
|
account: SessionAccount,
|
||||||
persistSessionCallback: (props: {
|
persistSessionCallback: (props: {
|
||||||
expired: boolean
|
expired: boolean
|
||||||
@@ -140,6 +141,7 @@ function createPersistSessionHandler(
|
|||||||
email: session?.email || account.email,
|
email: session?.email || account.email,
|
||||||
emailConfirmed: session?.emailConfirmed || account.emailConfirmed,
|
emailConfirmed: session?.emailConfirmed || account.emailConfirmed,
|
||||||
deactivated: isSessionDeactivated(session?.accessJwt),
|
deactivated: isSessionDeactivated(session?.accessJwt),
|
||||||
|
pdsUrl: agent.pdsUrl?.toString(),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tokens are undefined if the session expires, or if creation fails for
|
* Tokens are undefined if the session expires, or if creation fails for
|
||||||
@@ -268,12 +270,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
refreshJwt: agent.session.refreshJwt,
|
refreshJwt: agent.session.refreshJwt,
|
||||||
accessJwt: agent.session.accessJwt,
|
accessJwt: agent.session.accessJwt,
|
||||||
deactivated,
|
deactivated,
|
||||||
|
pdsUrl: agent.pdsUrl?.toString(),
|
||||||
}
|
}
|
||||||
|
|
||||||
await configureModeration(agent, account)
|
await configureModeration(agent, account)
|
||||||
|
|
||||||
agent.setPersistSessionHandler(
|
agent.setPersistSessionHandler(
|
||||||
createPersistSessionHandler(
|
createPersistSessionHandler(
|
||||||
|
agent,
|
||||||
account,
|
account,
|
||||||
({expired, refreshedAccount}) => {
|
({expired, refreshedAccount}) => {
|
||||||
upsertAccount(refreshedAccount, expired)
|
upsertAccount(refreshedAccount, expired)
|
||||||
@@ -320,6 +324,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
|
|
||||||
agent.setPersistSessionHandler(
|
agent.setPersistSessionHandler(
|
||||||
createPersistSessionHandler(
|
createPersistSessionHandler(
|
||||||
|
agent,
|
||||||
account,
|
account,
|
||||||
({expired, refreshedAccount}) => {
|
({expired, refreshedAccount}) => {
|
||||||
upsertAccount(refreshedAccount, expired)
|
upsertAccount(refreshedAccount, expired)
|
||||||
@@ -364,16 +369,19 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
async account => {
|
async account => {
|
||||||
logger.debug(`session: initSession`, {}, logger.DebugContext.session)
|
logger.debug(`session: initSession`, {}, logger.DebugContext.session)
|
||||||
|
|
||||||
const agent = new BskyAgent({
|
const agent = new BskyAgent({service: account.service})
|
||||||
service: account.service,
|
|
||||||
persistSession: createPersistSessionHandler(
|
agent.setPersistSessionHandler(
|
||||||
|
createPersistSessionHandler(
|
||||||
|
agent,
|
||||||
account,
|
account,
|
||||||
({expired, refreshedAccount}) => {
|
({expired, refreshedAccount}) => {
|
||||||
upsertAccount(refreshedAccount, expired)
|
upsertAccount(refreshedAccount, expired)
|
||||||
},
|
},
|
||||||
{networkErrorCallback: clearCurrentAccount},
|
{networkErrorCallback: clearCurrentAccount},
|
||||||
),
|
),
|
||||||
})
|
)
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (IS_DEV && isWeb) window.agent = agent
|
if (IS_DEV && isWeb) window.agent = agent
|
||||||
await configureModeration(agent, account)
|
await configureModeration(agent, account)
|
||||||
|
|||||||
Reference in New Issue
Block a user