Skip to content

Commit

Permalink
fix: attach token in hash mode
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 8, 2024
1 parent 6672e46 commit ebffb97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function setToken(token: string) {
export function removeToken() {
return Cookies.remove(TokenKey)
}

export const attachTokenFromQuery = () => {
const token = new URLSearchParams(window.location.search).get('token')
if (token) {
Expand All @@ -49,5 +48,29 @@ export const attachTokenFromQuery = () => {
query,
})
})
} else {
// hash mode

const hash = window.location.hash.slice(1)

const parsedUrl = new URL(hash, window.location.origin)
const token = parsedUrl.searchParams.get('token')
if (token) {
setToken(token)
setTokenIsUpstream(true)
parsedUrl.searchParams.delete('token')

router.isReady().then(() => {
const query = {} as any
for (const [key, value] of parsedUrl.searchParams.entries()) {
query[key] = value
}

router.replace({
path: parsedUrl.pathname,
query,
})
})
}
}
}
1 change: 1 addition & 0 deletions src/views/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { UpdatePanel } from './update-panel'

export const DashBoardView = defineComponent({
name: 'DashboardView',

setup() {
const stat = ref(
new Proxy(
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"skipDefaultLibCheck": true,
"lib": [
"esnext",
"dom"
"dom",
"dom.iterable"
],
"types": [],
"paths": {
Expand Down

0 comments on commit ebffb97

Please sign in to comment.