mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-24 20:59:29 +00:00
add store and base api
This commit is contained in:
21
src/services/auth/auth.ts
Normal file
21
src/services/auth/auth.ts
Normal 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
|
||||
1
src/services/auth/index.ts
Normal file
1
src/services/auth/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './auth.ts'
|
||||
13
src/services/store.ts
Normal file
13
src/services/store.ts
Normal 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>
|
||||
Reference in New Issue
Block a user