fix user refresher
This commit is contained in:
parent
17c9885ccc
commit
5f47162a50
6 changed files with 85 additions and 36 deletions
|
@ -2,6 +2,7 @@ import { dispatchMessage } from '../messageBus/messageBus.ts'
|
|||
import client from '../api/client.ts'
|
||||
import { ProblemDetails } from '../../types'
|
||||
import { SignupCode } from './signupCode.ts'
|
||||
import { User } from '../user/userStore.ts'
|
||||
|
||||
export class AuthService {
|
||||
constructor() {}
|
||||
|
@ -64,9 +65,9 @@ export class AuthService {
|
|||
return res.data.signupCodes.map(SignupCode.fromDto)
|
||||
}
|
||||
|
||||
async refreshUser(userId: string) {
|
||||
async refreshUser(userId: string): Promise<User | null> {
|
||||
if (this.getCookie('hasSession') !== 'true') {
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
const res = await client.GET(`/auth/user/{userId}`, {
|
||||
|
@ -76,11 +77,7 @@ export class AuthService {
|
|||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!res.data) {
|
||||
dispatchMessage('auth:user-refresh-failed', null)
|
||||
} else {
|
||||
dispatchMessage('auth:user-refreshed', { ...res.data })
|
||||
}
|
||||
return res.data ?? null
|
||||
}
|
||||
|
||||
private getCookie(cookieName: string): string | undefined {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue