mirror of
https://github.com/ershisan99/cards-front.git
synced 2025-12-16 20:49:28 +00:00
add auth api and auth instance
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -28,3 +28,9 @@ build
|
||||
|
||||
# Miscellaneous
|
||||
*.local
|
||||
|
||||
|
||||
# env
|
||||
|
||||
.env.development
|
||||
.env.production
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -7,6 +7,7 @@ import { createTheme, ThemeProvider } from "@mui/material"
|
||||
import { useAppDispatch, useAppSelector } from "@/app/hooks"
|
||||
import { useEffect } from "react"
|
||||
import { appActions } from "@/features/app/app.slice"
|
||||
import { instance } from "@/app/instance"
|
||||
|
||||
export const Test = () => {
|
||||
const isLoading = useAppSelector((state) => state.app.isLoading)
|
||||
@@ -21,6 +22,7 @@ export const Test = () => {
|
||||
setTimeout(() => {
|
||||
dispatch(appActions.setIsLoading({ isLoading: false }))
|
||||
}, 3000)
|
||||
instance.get("/ping")
|
||||
}, [dispatch])
|
||||
|
||||
if (isLoading) return <div>loading...</div>
|
||||
|
||||
9
src/app/instance.ts
Normal file
9
src/app/instance.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import axios from "axios"
|
||||
|
||||
export const instance = axios.create({
|
||||
baseURL:
|
||||
process.env.NODE_ENV === "development"
|
||||
? "http://localhost:7542/2.0/"
|
||||
: "https://neko-back.herokuapp.com/2.0/",
|
||||
withCredentials: true,
|
||||
})
|
||||
0
src/constants/api_url.ts
Normal file
0
src/constants/api_url.ts
Normal file
@@ -1,12 +1,16 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
|
||||
|
||||
const initialAppState = {
|
||||
error: null as null | string,
|
||||
isLoading: true,
|
||||
isAppInitialized: false,
|
||||
}
|
||||
|
||||
export type InitialAppState = typeof initialAppState
|
||||
|
||||
const slice = createSlice({
|
||||
name: "app",
|
||||
initialState: {
|
||||
error: null as null | string,
|
||||
isLoading: true,
|
||||
isAppInitialized: false,
|
||||
},
|
||||
initialState: initialAppState,
|
||||
reducers: {
|
||||
setIsLoading: (state, action: PayloadAction<{ isLoading: boolean }>) => {
|
||||
state.isLoading = action.payload.isLoading
|
||||
@@ -14,11 +18,11 @@ const slice = createSlice({
|
||||
setError: (state, action: PayloadAction<{ error: string | null }>) => {
|
||||
state.error = action.payload.error
|
||||
},
|
||||
setIsAppInitialized: (
|
||||
setAppInitialized: (
|
||||
state,
|
||||
action: PayloadAction<{ isInitialized: boolean }>,
|
||||
action: PayloadAction<{ isAppInitialized: boolean }>,
|
||||
) => {
|
||||
state.isAppInitialized = action.payload.isInitialized
|
||||
state.isAppInitialized = action.payload.isAppInitialized
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
7
src/features/auth/auth.api.ts
Normal file
7
src/features/auth/auth.api.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { AuthInstance } from "@/features/auth/auth.instance"
|
||||
|
||||
export const AuthApi = () => ({
|
||||
register: (params: any) => {
|
||||
return AuthInstance.post(params)
|
||||
},
|
||||
})
|
||||
6
src/features/auth/auth.instance.ts
Normal file
6
src/features/auth/auth.instance.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import axios from "axios"
|
||||
|
||||
export const AuthInstance = axios.create({
|
||||
baseURL: import.meta.env.BASE_URL + "auth/",
|
||||
withCredentials: true,
|
||||
})
|
||||
Reference in New Issue
Block a user