Projekt

Obecné

Profil

Stáhnout (805 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
import { createAsyncThunk } from "@reduxjs/toolkit"
2
import { axiosInstance } from "../../api/api"
3
import { loginRequest } from "../../api/authservice"
4

    
5
export const login = createAsyncThunk(
6
    "user/login",
7
    async (payload: { username: string, password: string }) => {
8
        try {
9
            const response = await loginRequest(payload.username, payload.password)
10
            console.log(response)
11
            if (response.status === 200) {
12
                return {
13
                    username: payload.username,
14
                    role: response.data.role
15
                }
16
            } else {
17
                return Promise.reject(response.data ? response.data : "Login failed")
18
            }
19
        } catch (err: any) {
20
            return Promise.reject(err.response.data)
21
        }
22
    }
23
)
    (1-1/1)