Skip to content

Commit

Permalink
fix: login validation
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Mar 26, 2023
1 parent 2c35916 commit 8426eba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/atoms/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { apiClient } from '~/utils/client'

import { useUserStore } from './user'

import './dev'
// import './dev'

export interface ViewportRecord {
w: number
Expand Down
6 changes: 4 additions & 2 deletions src/atoms/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export const useUserStore = create<UserState & UserAction>(
setState({ token: null })
return
}
setState({ token })
setState({ token, isLogged: true })

useAppStore.getState().fetchUrl()
requestAnimationFrame(() => {
useAppStore.getState().fetchUrl()
})
},
setUser(model) {
setState({ master: model })
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/use-check-logged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useThemeConfig } from './use-initial-data'
export const useCheckLogged = () => {
const userStore = useUserStore.getState()

const master = userStore.master
const {
function: {
banDevtool: { enable: banDevtoolEnable },
Expand All @@ -30,7 +29,10 @@ export const useCheckLogged = () => {
.put<{ token: string }>()
.then((res) => {
userStore.setToken(res.token)
message.success(`欢迎回来,${master!.name}`, 1500)
message.success(
`欢迎回来,${useUserStore.getState().master!.name}`,
1500,
)
setToken(res.token)
})
} else {
Expand Down
1 change: 1 addition & 0 deletions src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const LoginView: NextPage = () => {
Router.push('/')
}
message.success('登录成功')

useUserStore.getState().setToken(data.token)
releaseDevtool()
}
Expand Down

0 comments on commit 8426eba

Please sign in to comment.