Revize d963a25c
Přidáno uživatelem Michal Schwob před více než 1 rok
src/api/authservice.ts | ||
---|---|---|
12 | 12 |
} |
13 | 13 |
|
14 | 14 |
export const isAuthRequest = async () => { |
15 |
Toast.show({ |
|
16 |
title: `Checking auth ${axiosInstance.defaults.baseURL}`, |
|
17 |
duration: 10000 |
|
18 |
}) |
|
19 | 15 |
return await axiosInstance.get( |
20 | 16 |
"/isauth" |
21 | 17 |
) |
src/pages/LoginPage.tsx | ||
---|---|---|
1 | 1 |
import { |
2 | 2 |
Center, |
3 |
Box, |
|
4 | 3 |
Heading, |
5 | 4 |
VStack, |
6 | 5 |
FormControl, |
7 |
Link, |
|
8 | 6 |
Input, |
9 | 7 |
Button, |
10 |
HStack, |
|
11 | 8 |
Text, |
12 |
KeyboardAvoidingView, useToast, ScrollView |
|
9 |
KeyboardAvoidingView, |
|
10 |
useToast |
|
13 | 11 |
} from "native-base" |
14 |
import { useCallback, useEffect, useState } from "react"
|
|
12 |
import { useEffect, useState } from "react" |
|
15 | 13 |
import { useDispatch, useSelector } from "react-redux" |
16 | 14 |
import { checkAuth, login } from "../stores/actions/userThunks" |
17 | 15 |
import { AppDispatch, RootState } from "../stores/store" |
18 | 16 |
import { Platform } from "react-native" |
19 | 17 |
import { log } from "../logging/logger" |
20 |
import * as SplashScreen from "expo-splash-screen" |
|
21 | 18 |
import { ApplicationHeading } from "../components/reusables/ApplicationHeading" |
22 |
import {consumeError} from "../stores/reducers/userSlice" |
|
23 | 19 |
|
24 | 20 |
|
25 | 21 |
const LoginPage = () => { |
... | ... | |
48 | 44 |
placement: "top", |
49 | 45 |
duration: 3000, |
50 | 46 |
}) |
51 |
// dispatch(consumeError()) |
|
52 | 47 |
} |
53 | 48 |
}, [lastError]); |
54 | 49 |
|
... | ... | |
58 | 53 |
flex={ 1 } |
59 | 54 |
justifyContent={ "center" } |
60 | 55 |
h={ {lg: "auto"} } |
61 |
// behavior={ "padding" } |
|
62 | 56 |
keyboardVerticalOffset={ 100 } |
63 | 57 |
> |
64 | 58 |
|
... | ... | |
88 | 82 |
Please log in to continue |
89 | 83 |
</Text> |
90 | 84 |
{ lastError && ( |
91 |
<ScrollView> |
|
92 |
<Text |
|
93 |
mt="1" |
|
94 |
textAlign="center" |
|
95 |
color="error.500" |
|
96 |
> |
|
97 |
{ lastError } |
|
98 |
</Text> |
|
99 |
</ScrollView> |
|
85 |
<Text |
|
86 |
mt="1" |
|
87 |
textAlign="center" |
|
88 |
color="error.500" |
|
89 |
> |
|
90 |
{ lastError } |
|
91 |
</Text> |
|
100 | 92 |
) } |
101 | 93 |
|
102 | 94 |
<VStack space={ 3 } > |
src/stores/actions/userThunks.ts | ||
---|---|---|
1 | 1 |
import { createAsyncThunk } from "@reduxjs/toolkit" |
2 | 2 |
import { isAuthRequest, loginRequest, logoutRequest } from "../../api/authservice" |
3 | 3 |
import { log } from "../../logging/logger" |
4 |
import {Toast} from "native-base" |
|
5 | 4 |
|
6 | 5 |
export const login = createAsyncThunk( |
7 | 6 |
"user/login", |
... | ... | |
16 | 15 |
role: response.data.role |
17 | 16 |
} |
18 | 17 |
} else { |
19 |
Toast.show({ |
|
20 |
title: `Login not 200 (${response.status}): ${response}`, |
|
21 |
duration: 10000 |
|
22 |
}) |
|
23 | 18 |
return Promise.reject(response.data ? response.data : "Login failed") |
24 | 19 |
} |
25 | 20 |
} catch (err: any) { |
26 |
Toast.show({ |
|
27 |
title: `Login err: ${err}`, |
|
28 |
duration: 10000 |
|
29 |
}) |
|
30 |
return Promise.reject(err.response ? err.response.data : "Something went wrong" + err) |
|
21 |
return Promise.reject(err.response ? err.response.data : "Something went wrong: " + err) |
|
31 | 22 |
} |
32 | 23 |
} |
33 | 24 |
) |
... | ... | |
39 | 30 |
const response = await isAuthRequest() |
40 | 31 |
console.log(response) |
41 | 32 |
if (response.status === 200) { |
42 |
Toast.show({ |
|
43 |
title: `Auth ok: ${response.data}`, |
|
44 |
duration: 10000 |
|
45 |
}) |
|
46 | 33 |
return { |
47 | 34 |
isLogged: response.data.isauth |
48 | 35 |
} |
49 | 36 |
} else { |
50 |
Toast.show({ |
|
51 |
title: `Auth err: ${response.data ? response.data : "Check authentication failed"}`, |
|
52 |
duration: 10000 |
|
53 |
}) |
|
54 | 37 |
return Promise.reject(response.data ? response.data : "Check authentication failed") |
55 | 38 |
} |
56 | 39 |
} catch (err: any) { |
57 |
Toast.show({ |
|
58 |
title: `Auth config: ${err.config}`, |
|
59 |
duration: 10000 |
|
60 |
}) |
|
61 |
|
|
62 |
Toast.show({ |
|
63 |
title: `Auth message: ${err.message}`, |
|
64 |
duration: 10000 |
|
65 |
}) |
|
66 |
return Promise.reject(`response: ${JSON.stringify(err.response?.data)}, request: ${JSON.stringify(err.request)}, config: ${JSON.stringify(err.config)}` ) |
|
40 |
return Promise.reject(err.response ? err.response.data : "Something went wrong: " + err) |
|
67 | 41 |
} |
68 | 42 |
} |
69 | 43 |
) |
Také k dispozici: Unified diff
REVERT: reverting debug toasts
re #10822