Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0efa284e

Přidáno uživatelem Fantič před asi 2 roky(ů)

#re 10343 Check authentication request added

Zobrazit rozdíly:

src/stores/actions/userThunks.ts
1 1
import { createAsyncThunk } from "@reduxjs/toolkit"
2
import { axiosInstance } from "../../api/api"
3
import { loginRequest } from "../../api/authservice"
2
import { isAuthRequest, loginRequest } from "../../api/authservice"
4 3

  
5 4
export const login = createAsyncThunk(
6 5
    "user/login",
......
20 19
            return Promise.reject(err.response.data)
21 20
        }
22 21
    }
22
)
23

  
24
export const checkAuth = createAsyncThunk(
25
    "user/isauth",
26
    async (payload: {
27
        isauth: boolean
28
    }) => {
29
        try {
30
            const response = await isAuthRequest()
31
            console.log(response)
32
            if (response.status === 200) {
33
                return {
34
                    isLogged: payload.isauth
35
                }
36
            } else {
37
                return Promise.reject(response.data ? response.data : "Check authentication failed")
38
            }
39
        } catch (err: any) {
40
            return Promise.reject(err.response.data)
41
        }
42
    }
23 43
)

Také k dispozici: Unified diff