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:
@@ -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'})
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user