Skip to content

Commit aedcda8

Browse files
Fix Cloudflare Access logout (#20)
1 parent 5ea3bcd commit aedcda8

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

packages/workshop-frontend/src/useAuth.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export function useAuth(publicApi: RpcStub<PublicApi>) {
9494
}
9595

9696
const logout = () => {
97+
if (CF_ACCESS_MODE) {
98+
window.location.assign('/cdn-cgi/access/logout')
99+
return
100+
}
101+
97102
// Use functional updater to read current state (avoids stale closure).
98103
setAuthState(prev => {
99104
if (prev.authenticatedApi) {
@@ -107,9 +112,7 @@ export function useAuth(publicApi: RpcStub<PublicApi>) {
107112
}
108113
})
109114

110-
if (!CF_ACCESS_MODE) {
111-
localStorage.removeItem('authToken')
112-
}
115+
localStorage.removeItem('authToken')
113116
}
114117

115118
return {
@@ -118,4 +121,4 @@ export function useAuth(publicApi: RpcStub<PublicApi>) {
118121
logout,
119122
isAuthenticated: !!authState.authenticatedApi
120123
}
121-
}
124+
}

0 commit comments

Comments
 (0)