Skip to content

Commit

Permalink
fix: socket connection
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Feb 2, 2024
1 parent 78515b2 commit cbb459b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/router/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ router.beforeEach(async (to) => {
if (!ok) {
return `/login?from=${encodeURI(to.fullPath)}`
} else {
import('socket').then((mo) => {
mo.socket.initIO()
})

const sessionWithLogin = sessionStorage.getItem(SESSION_WITH_LOGIN)
if (sessionWithLogin) return
// login with token only
Expand Down
3 changes: 2 additions & 1 deletion src/socket/socket-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import io from 'socket.io-client'
import { getToken } from 'utils/auth'
import { bus } from 'utils/event-bus'
import { BrowserNotification } from 'utils/notification'
import type { NotificationTypes } from './types'

import { configs } from '../configs'
import type { NotificationTypes } from './types'
import { EventTypes } from './types'

const Notification = {
Expand Down Expand Up @@ -45,6 +45,7 @@ export class SocketClient {
}
this.destory()
const token = getToken()

if (!token) {
return
}
Expand Down

0 comments on commit cbb459b

Please sign in to comment.