fix user refresh
This commit is contained in:
parent
0b2a64e449
commit
cc3d138fd3
6 changed files with 6 additions and 13 deletions
|
@ -8,9 +8,6 @@ export function initClient(): ApiClient {
|
|||
const client = createClient<paths>({ baseUrl: import.meta.env.VITE_API_URL })
|
||||
const UnauthorizedHandlerMiddleware: Middleware = {
|
||||
async onResponse({ response }) {
|
||||
console.debug('on response middleware?')
|
||||
console.debug(response.headers.getSetCookie())
|
||||
console.debug(response.headers.get('set-cookie'))
|
||||
if (response.status === 401) {
|
||||
dispatchMessage('auth:unauthorized', null)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { dispatchMessage } from '../messageBus/messageBus.ts'
|
||||
import { ProblemDetails } from '../../types'
|
||||
import { SignupCode } from './signupCode.ts'
|
||||
import { getCookie } from './cookies.ts'
|
||||
import { ApiClient } from '../api/client.ts'
|
||||
|
||||
export class AuthService {
|
||||
|
@ -66,10 +65,6 @@ export class AuthService {
|
|||
}
|
||||
|
||||
async refreshUser(userId: string) {
|
||||
if (getCookie('hasSession') !== 'true') {
|
||||
return null
|
||||
}
|
||||
|
||||
await this.client.GET(`/auth/user/{userId}`, {
|
||||
params: {
|
||||
path: { userId },
|
||||
|
|
|
@ -18,7 +18,7 @@ export default function RefreshUser({
|
|||
if (didRefresh.current) return
|
||||
if (user == null) return
|
||||
didRefresh.current = true
|
||||
await authService.refreshUser(user.userId)
|
||||
await authService.refreshUser(user.id)
|
||||
})
|
||||
return () => clearTimeout(timeoutId)
|
||||
}, [authService, user])
|
||||
|
|
|
@ -52,7 +52,7 @@ export default function HomePage({ postsService, mediaService }: HomePageProps)
|
|||
}
|
||||
}),
|
||||
)
|
||||
const postId = await postsService.createNew(user.userId, content, media, isPublic)
|
||||
const postId = await postsService.createNew(user.id, content, media, isPublic)
|
||||
const post = new Post(postId, content, media, Temporal.Now.instant(), user.username)
|
||||
setPages((pages) => [[post], ...pages])
|
||||
} catch (error) {
|
||||
|
|
|
@ -5,9 +5,9 @@ import { useState } from 'react'
|
|||
import { setGlobal } from '../femtoApp.ts'
|
||||
|
||||
export interface User {
|
||||
userId: string
|
||||
id: string
|
||||
username: string
|
||||
isSuperUser: boolean
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
let globalUser: User | null
|
||||
|
|
|
@ -5,7 +5,7 @@ import { AuthService } from './app/auth/authService.ts'
|
|||
// Starts a loop that pings the server to keep the session alive, while also getting any updates on the user profile
|
||||
export function useRefreshSessionLoop(authService: AuthService) {
|
||||
const user = useUser()
|
||||
const userId = user?.userId ?? null
|
||||
const userId = user?.id ?? null
|
||||
|
||||
useEffect(() => {
|
||||
if (userId == null) {
|
||||
|
@ -17,6 +17,7 @@ export function useRefreshSessionLoop(authService: AuthService) {
|
|||
timeouts.push(
|
||||
setTimeout(async function refreshUser() {
|
||||
await authService.refreshUser(userId)
|
||||
|
||||
timeouts.push(setTimeout(refreshUser, 60_000))
|
||||
}),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue