init frontend

This commit is contained in:
2023-09-27 20:27:25 +01:00
parent 4aa5cd6dfc
commit 9e6659c14e
63 changed files with 4901 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { apiSlice } from '../features/api'
import { convertRawAuthData } from '../types/auth'
import type { AuthData } from '../types/common'
import type { LoginRequest, RawAuthResponse } from '../types/auth'
export const authApiSlice = apiSlice.injectEndpoints({
endpoints: (builder) => ({
login: builder.mutation<AuthData, LoginRequest>({
query: data => ({
url: '/v1/auth/login',
method: 'POST',
body: { ...data }
}),
transformResponse: (response: RawAuthResponse) => {
if (response.data === undefined) { throw Error('invalid auth response') }
return convertRawAuthData(response.data)
},
}),
})
})
export const { useLoginMutation } = authApiSlice