refresh user

This commit is contained in:
john 2025-05-19 09:23:15 +02:00
parent 57e56dc33d
commit 17c9885ccc
6 changed files with 127 additions and 20 deletions

View file

@ -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
}
}