Modified code so that the user is signed out of a selected account rather than all accounts.

Feature Request: https://github.com/bluesky-social/social-app/issues/4775
Bug: https://github.com/bluesky-social/social-app/issues/4683
This commit is contained in:
Swaroop Rao
2024-07-12 17:34:53 -04:00
parent 3627a249ff
commit 0c09fdcfe3
2 changed files with 14 additions and 5 deletions
+1
View File
@@ -120,6 +120,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
cancelPendingTask()
dispatch({
type: 'logged-out',
accountDid: account.did,
})
logEvent('account:loggedOut', {logContext})
addSessionDebugLog({type: 'method:end', method: 'logout'})
+13 -5
View File
@@ -143,12 +143,20 @@ let reducer = (state: State, action: Action): State => {
}
}
case 'logged-out': {
//Fetch the account ID that the user signed out from
const {accountDid} = action
//Find the account for which the tokens need to be cleared
const loggedOutAccount = state.accounts.filter(a => a.did === accountDid)
//Clear the tokens for the account that the user signed out from
loggedOutAccount.accessJwt = undefined
loggedOutAccount.refreshJwt = undefined
return {
accounts: state.accounts.map(a => ({
...a,
// Clear tokens for *every* account (this is a hard logout).
refreshJwt: undefined,
accessJwt: undefined,
//Return all the accounts. The other accounts remain unchanged, so the user will
//stay signed in on them.
accounts: state.accounts
})),
currentAgentState: createPublicAgentState(),
needsPersist: true,