mirror of
https://github.com/hexolan/panels.git
synced 2026-03-26 20:41:15 +00:00
init frontend
This commit is contained in:
24
services/frontend/src/app/api/auth.ts
Normal file
24
services/frontend/src/app/api/auth.ts
Normal 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
|
||||
Reference in New Issue
Block a user