refresh user
This commit is contained in:
parent
57e56dc33d
commit
17c9885ccc
6 changed files with 127 additions and 20 deletions
|
@ -63,4 +63,35 @@ export class AuthService {
|
|||
|
||||
return res.data.signupCodes.map(SignupCode.fromDto)
|
||||
}
|
||||
|
||||
async refreshUser(userId: string) {
|
||||
if (this.getCookie('hasSession') !== 'true') {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await client.GET(`/auth/user/{userId}`, {
|
||||
params: {
|
||||
path: { userId },
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!res.data) {
|
||||
dispatchMessage('auth:user-refresh-failed', null)
|
||||
} else {
|
||||
dispatchMessage('auth:user-refreshed', { ...res.data })
|
||||
}
|
||||
}
|
||||
|
||||
private getCookie(cookieName: string): string | undefined {
|
||||
const cookie = document.cookie
|
||||
.split('; ')
|
||||
.map((c) => {
|
||||
const [name, value] = c.split('=')
|
||||
return { name, value }
|
||||
})
|
||||
.find((c) => c.name === cookieName)
|
||||
|
||||
return cookie?.value
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue