Skip to content

Commit

Permalink
fix: update logout function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyiming0803 committed Aug 25, 2022
1 parent f504a5e commit e65864a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/guard/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GuardOptions } from '@authing/guard'

export const guardOptions: GuardOptions = {
appId: '62e8d32e4feac0ba0a75edf5',
appId: '62e7f0c91073aaba0db4d65b',
// host: 'https://ipehegkanbpgkdho-demo.authing.cn',
align: 'center'
}
6 changes: 6 additions & 0 deletions examples/guard/src/pages/Jump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ export default function Jump() {

const onLogin = () => guard.startWithRedirect()

const checkLoginStatus = async () => {
const user = await guard.checkLoginStatus()
console.log('user: ', user)
}

return (
<div>
<div>
<button onClick={onLogin}>登录</button>
<button onClick={checkLoginStatus}>checkLoginStatus</button>
</div>
</div>
)
Expand Down
11 changes: 7 additions & 4 deletions examples/guard/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default function Login () {
guardEffects()
}, [])

const checkLoginStatus = async () => {
const user = await guard.checkLoginStatus()
console.log('user: ', user)
}

const onmountGuard = () => guard.unmount()

const startRegister = () => guard.startRegister()
Expand All @@ -55,10 +60,7 @@ export default function Login () {
console.log('userInfo: ', userInfo)
}

const checkLoginStatus = async () => {
const user = await guard.checkLoginStatus()
console.log('user: ', user)
}
const onLogout = () => guard.logout()

return <>
<div style={{ marginBottom: '100px' }}>
Expand All @@ -67,6 +69,7 @@ export default function Login () {
<button onClick={changeLang}>changeLang</button>
<button onClick={getUserInfo}>getUserInfo</button>
<button onClick={checkLoginStatus}>checkLoginStatus</button>
<button onClick={onLogout}>onLogout</button>
</div>

<div id="guard-container"></div>
Expand Down
12 changes: 11 additions & 1 deletion packages/guard/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,22 @@ export class Guard {
}

async logout() {
const redirectUri = window.location.origin
const publicConfig = await this.then()

let redirectUri = ''
try {
redirectUri = publicConfig.logoutRedirectUris[0]
} catch (e) {
redirectUri = window.location.origin
}

const idToken = localStorage.getItem('idToken')
let logoutUrl = ''

const authClient = await this.getAuthClient()

authClient.logout()

if (idToken) {
logoutUrl = authClient.buildLogoutUrl({
expert: true,
Expand Down

0 comments on commit e65864a

Please sign in to comment.