I have two app, both calls their me
endpoint. In one case there is an OPTION call before too. Why is it an OPTION request before, and when it is no?
In this app there is NO OPTION
request:
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
useEffect(() => {
store?.dispatch(me({}))
}, [])
export const me = createAsyncThunk(
`${namespace}/me`,
async (props: any, { dispatch, getState }) => {
const { data } = await axios({
method: 'get',
url: 'me',
headers: { crossDomain: true },
Here there is OPTION before:
const AuthProvider = ({ children }: Props) => {
// ** States
const [user, setUser] = useState<UserDataType | null>(defaultProvider.user)
const [loading, setLoading] = useState<boolean>(defaultProvider.loading)
const [isInitialized, setIsInitialized] = useState<boolean>(
defaultProvider.isInitialized
)
// ** Hooks
const router = useRouter()
useEffect(() => {
const initAuth = async (): Promise<void> => {
setIsInitialized(true)
setLoading(true)
await axios
.get(authConfig.meEndpoint, {
headers: { crossDomain: true },
})
.then(async (response) => {
setLoading(false)
setUser({ ...response.data })
})
.catch(() => {
/*localStorage.removeItem('userData')
localStorage.removeItem('refreshToken')
localStorage.removeItem('accessToken')
setUser(null)*/
setLoading(false)
})
}
initAuth()
}, [])
Both has a reverse proxy, in dev mode they redirect to 127.0.0.1:8080.