Skip to content

Commit

Permalink
fix: verify token
Browse files Browse the repository at this point in the history
  • Loading branch information
xjh22222228 committed Nov 20, 2022
1 parent 584fb88 commit d5955fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { queryString, setLocation } from '../utils'
import { en_US, NzI18nService, zh_CN } from 'ng-zorro-antd/i18n'
import { getLocale } from 'src/locale'
import { settings } from 'src/store'
import { verifyToken } from 'src/services'
import { getToken, removeToken } from 'src/utils/user'

@Component({
selector: 'app-xiejiahe',
Expand All @@ -29,6 +31,14 @@ export class AppComponent {
} else {
this.i18n.setLocale(en_US);
}

const token = getToken()
if (token) {
verifyToken(token).catch(() => {
removeToken()
location.reload()
})
}
}

goRoute() {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export function setToken(token: string) {
return window.localStorage.setItem('token', token)
}

export function removeToken() {
return window.localStorage.removeItem('token')
}

export const isLogin: boolean = !!getToken()

0 comments on commit d5955fd

Please sign in to comment.