add store and base api

This commit is contained in:
2023-08-05 14:58:27 +02:00
parent 8d75b18f61
commit 6988feae78
7 changed files with 161 additions and 4 deletions

21
src/services/auth/auth.ts Normal file
View File

@@ -0,0 +1,21 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
export const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: 'http://localhost:3333',
credentials: 'include',
prepareHeaders: headers => {
headers.append('x-auth-skip', 'true')
},
}),
endpoints: builder => {
return {
getMe: builder.query<any, void>({
query: () => `v1/decks`,
}),
}
},
})
export const { useGetMeQuery } = api

View File

@@ -0,0 +1 @@
export * from './auth.ts'

13
src/services/store.ts Normal file
View File

@@ -0,0 +1,13 @@
import { configureStore } from '@reduxjs/toolkit'
import { api } from '@/services/auth'
export const store = configureStore({
reducer: {
[api.reducerPath]: api.reducer,
},
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(api.middleware),
})
export type AppDispatch = typeof store.dispatch
export type RootState = ReturnType<typeof store.getState>