Rename logout to logoutEveryAccount
This commit is contained in:
@@ -14,6 +14,7 @@ export type LogEvents = {
|
|||||||
}
|
}
|
||||||
'account:loggedOut': {
|
'account:loggedOut': {
|
||||||
logContext: 'SwitchAccount' | 'Settings' | 'SignupQueued' | 'Deactivated'
|
logContext: 'SwitchAccount' | 'Settings' | 'SignupQueued' | 'Deactivated'
|
||||||
|
scope: 'current' | 'every'
|
||||||
}
|
}
|
||||||
'notifications:openApp': {}
|
'notifications:openApp': {}
|
||||||
'notifications:request': {
|
'notifications:request': {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function Deactivated() {
|
|||||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||||
const hasOtherAccounts = accounts.length > 1
|
const hasOtherAccounts = accounts.length > 1
|
||||||
const setMinimalShellMode = useSetMinimalShellMode()
|
const setMinimalShellMode = useSetMinimalShellMode()
|
||||||
const {logout} = useSessionApi()
|
const {logoutEveryAccount} = useSessionApi()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const [pending, setPending] = React.useState(false)
|
const [pending, setPending] = React.useState(false)
|
||||||
const [error, setError] = React.useState<string | undefined>()
|
const [error, setError] = React.useState<string | undefined>()
|
||||||
@@ -72,8 +72,8 @@ export function Deactivated() {
|
|||||||
// So we change the URL ourselves. The navigator will pick it up on remount.
|
// So we change the URL ourselves. The navigator will pick it up on remount.
|
||||||
history.pushState(null, '', '/')
|
history.pushState(null, '', '/')
|
||||||
}
|
}
|
||||||
logout('Deactivated')
|
logoutEveryAccount('Deactivated')
|
||||||
}, [logout])
|
}, [logoutEveryAccount])
|
||||||
|
|
||||||
const handleActivate = React.useCallback(async () => {
|
const handleActivate = React.useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function DeactivateAccountDialogInner({
|
|||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const {logout} = useSessionApi()
|
const {logoutEveryAccount} = useSessionApi()
|
||||||
const [pending, setPending] = React.useState(false)
|
const [pending, setPending] = React.useState(false)
|
||||||
const [error, setError] = React.useState<string | undefined>()
|
const [error, setError] = React.useState<string | undefined>()
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ function DeactivateAccountDialogInner({
|
|||||||
setPending(true)
|
setPending(true)
|
||||||
await agent.com.atproto.server.deactivateAccount({})
|
await agent.com.atproto.server.deactivateAccount({})
|
||||||
control.close(() => {
|
control.close(() => {
|
||||||
logout('Deactivated')
|
logoutEveryAccount('Deactivated')
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
switch (e.message) {
|
switch (e.message) {
|
||||||
@@ -66,7 +66,7 @@ function DeactivateAccountDialogInner({
|
|||||||
} finally {
|
} finally {
|
||||||
setPending(false)
|
setPending(false)
|
||||||
}
|
}
|
||||||
}, [agent, control, logout, _, setPending])
|
}, [agent, control, logoutEveryAccount, _, setPending])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function SignupQueued() {
|
|||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
const onboardingDispatch = useOnboardingDispatch()
|
const onboardingDispatch = useOnboardingDispatch()
|
||||||
const {logout} = useSessionApi()
|
const {logoutEveryAccount} = useSessionApi()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
|
||||||
const [isProcessing, setProcessing] = React.useState(false)
|
const [isProcessing, setProcessing] = React.useState(false)
|
||||||
@@ -153,7 +153,7 @@ export function SignupQueued() {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="large"
|
size="large"
|
||||||
label={_(msg`Log out`)}
|
label={_(msg`Log out`)}
|
||||||
onPress={() => logout('SignupQueued')}>
|
onPress={() => logoutEveryAccount('SignupQueued')}>
|
||||||
<ButtonText style={[{color: t.palette.primary_500}]}>
|
<ButtonText style={[{color: t.palette.primary_500}]}>
|
||||||
<Trans>Log out</Trans>
|
<Trans>Log out</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
@@ -182,7 +182,7 @@ export function SignupQueued() {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="large"
|
size="large"
|
||||||
label={_(msg`Log out`)}
|
label={_(msg`Log out`)}
|
||||||
onPress={() => logout('SignupQueued')}>
|
onPress={() => logoutEveryAccount('SignupQueued')}>
|
||||||
<ButtonText style={[{color: t.palette.primary_500}]}>
|
<ButtonText style={[{color: t.palette.primary_500}]}>
|
||||||
<Trans>Log out</Trans>
|
<Trans>Log out</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ describe('session', () => {
|
|||||||
|
|
||||||
state = run(state, [
|
state = run(state, [
|
||||||
{
|
{
|
||||||
type: 'logged-out',
|
type: 'logged-out-every-account',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
// Should keep the account but clear out the tokens.
|
// Should keep the account but clear out the tokens.
|
||||||
@@ -372,7 +372,7 @@ describe('session', () => {
|
|||||||
state = run(state, [
|
state = run(state, [
|
||||||
{
|
{
|
||||||
// Log everyone out.
|
// Log everyone out.
|
||||||
type: 'logged-out',
|
type: 'logged-out-every-account',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
expect(state.accounts.length).toBe(3)
|
expect(state.accounts.length).toBe(3)
|
||||||
@@ -466,7 +466,7 @@ describe('session', () => {
|
|||||||
|
|
||||||
state = run(state, [
|
state = run(state, [
|
||||||
{
|
{
|
||||||
type: 'logged-out',
|
type: 'logged-out-every-account',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
expect(state.accounts.length).toBe(1)
|
expect(state.accounts.length).toBe(1)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const AgentContext = React.createContext<BskyAgent | null>(null)
|
|||||||
const ApiContext = React.createContext<SessionApiContext>({
|
const ApiContext = React.createContext<SessionApiContext>({
|
||||||
createAccount: async () => {},
|
createAccount: async () => {},
|
||||||
login: async () => {},
|
login: async () => {},
|
||||||
logout: async () => {},
|
logoutEveryAccount: async () => {},
|
||||||
resumeSession: async () => {},
|
resumeSession: async () => {},
|
||||||
removeAccount: () => {},
|
removeAccount: () => {},
|
||||||
})
|
})
|
||||||
@@ -115,14 +115,16 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
[onAgentSessionChange, cancelPendingTask],
|
[onAgentSessionChange, cancelPendingTask],
|
||||||
)
|
)
|
||||||
|
|
||||||
const logout = React.useCallback<SessionApiContext['logout']>(
|
const logoutEveryAccount = React.useCallback<
|
||||||
|
SessionApiContext['logoutEveryAccount']
|
||||||
|
>(
|
||||||
logContext => {
|
logContext => {
|
||||||
addSessionDebugLog({type: 'method:start', method: 'logout'})
|
addSessionDebugLog({type: 'method:start', method: 'logout'})
|
||||||
cancelPendingTask()
|
cancelPendingTask()
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'logged-out',
|
type: 'logged-out-every-account',
|
||||||
})
|
})
|
||||||
logEvent('account:loggedOut', {logContext})
|
logEvent('account:loggedOut', {logContext, scope: 'every'})
|
||||||
addSessionDebugLog({type: 'method:end', method: 'logout'})
|
addSessionDebugLog({type: 'method:end', method: 'logout'})
|
||||||
},
|
},
|
||||||
[cancelPendingTask],
|
[cancelPendingTask],
|
||||||
@@ -230,11 +232,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
() => ({
|
() => ({
|
||||||
createAccount,
|
createAccount,
|
||||||
login,
|
login,
|
||||||
logout,
|
logoutEveryAccount,
|
||||||
resumeSession,
|
resumeSession,
|
||||||
removeAccount,
|
removeAccount,
|
||||||
}),
|
}),
|
||||||
[createAccount, login, logout, resumeSession, removeAccount],
|
[createAccount, login, logoutEveryAccount, resumeSession, removeAccount],
|
||||||
)
|
)
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export type Action =
|
|||||||
accountDid: string
|
accountDid: string
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'logged-out'
|
type: 'logged-out-every-account'
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'synced-accounts'
|
type: 'synced-accounts'
|
||||||
@@ -138,7 +138,7 @@ let reducer = (state: State, action: Action): State => {
|
|||||||
needsPersist: true,
|
needsPersist: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'logged-out': {
|
case 'logged-out-every-account': {
|
||||||
return {
|
return {
|
||||||
accounts: state.accounts.map(a => ({
|
accounts: state.accounts.map(a => ({
|
||||||
...a,
|
...a,
|
||||||
|
|||||||
@@ -29,12 +29,9 @@ export type SessionApiContext = {
|
|||||||
},
|
},
|
||||||
logContext: LogEvents['account:loggedIn']['logContext'],
|
logContext: LogEvents['account:loggedIn']['logContext'],
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
/**
|
logoutEveryAccount: (
|
||||||
* A full logout. Clears the `currentAccount` from session, AND removes
|
logContext: LogEvents['account:loggedOut']['logContext'],
|
||||||
* access tokens from all accounts, so that returning as any user will
|
) => void
|
||||||
* require a full login.
|
|
||||||
*/
|
|
||||||
logout: (logContext: LogEvents['account:loggedOut']['logContext']) => void
|
|
||||||
resumeSession: (account: SessionAccount) => Promise<void>
|
resumeSession: (account: SessionAccount) => Promise<void>
|
||||||
removeAccount: (account: SessionAccount) => void
|
removeAccount: (account: SessionAccount) => void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const BTN = {height: 1, width: 1, backgroundColor: 'red'}
|
|||||||
|
|
||||||
export function TestCtrls() {
|
export function TestCtrls() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {logout, login} = useSessionApi()
|
const {logoutEveryAccount, login} = useSessionApi()
|
||||||
const {openModal} = useModalControls()
|
const {openModal} = useModalControls()
|
||||||
const onboardingDispatch = useOnboardingDispatch()
|
const onboardingDispatch = useOnboardingDispatch()
|
||||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||||
@@ -60,7 +60,7 @@ export function TestCtrls() {
|
|||||||
/>
|
/>
|
||||||
<Pressable
|
<Pressable
|
||||||
testID="e2eSignOut"
|
testID="e2eSignOut"
|
||||||
onPress={() => logout('Settings')}
|
onPress={() => logoutEveryAccount('Settings')}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
style={BTN}
|
style={BTN}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function SettingsAccountCard({
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {logout} = useSessionApi()
|
const {logoutEveryAccount} = useSessionApi()
|
||||||
const {data: profile} = useProfileQuery({did: account.did})
|
const {data: profile} = useProfileQuery({did: account.did})
|
||||||
const isCurrentAccount = account.did === currentAccount?.did
|
const isCurrentAccount = account.did === currentAccount?.did
|
||||||
|
|
||||||
@@ -109,11 +109,11 @@ function SettingsAccountCard({
|
|||||||
testID="signOutBtn"
|
testID="signOutBtn"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (isNative) {
|
if (isNative) {
|
||||||
logout('Settings')
|
logoutEveryAccount('Settings')
|
||||||
resetToTab('HomeTab')
|
resetToTab('HomeTab')
|
||||||
} else {
|
} else {
|
||||||
navigate('Home').then(() => {
|
navigate('Home').then(() => {
|
||||||
logout('Settings')
|
logoutEveryAccount('Settings')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user