-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.text
63 lines (52 loc) · 1.54 KB
/
fetch.text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { setAuthState } from "@/redux/features/auth-slice";
import { getCookie } from "cookies-next";
import axios from "axios";
import { useDispatch } from "react-redux";
import { AppDispatch } from "@/redux/store";
const dispatch = useDispatch<AppDispatch>();
// ---------------------------------------------------------------
// const fetchUser = async () => {
// dispatch(
// setAuthState({
// loading: true,
// data: null,
// error: null,
// })
// );
// try {
// const jwt = getCookie("jwt");
// console.log("jwt in try", jwt);
// if (!jwt) {
// dispatch(
// setAuthState({
// loading: false,
// data: null,
// error: null,
// })
// );
// const response = await axios.get("http://localhost:3000/api/auth/me", {
// headers: {
// Authorization: `Bearer ${jwt}`,
// },
// });
// axios.defaults.headers.common["Authorization"] = `Bearer ${jwt}`;
// dispatch(
// setAuthState({
// loading: false,
// data: response.data,
// error: null,
// })
// );
// }
// } catch (error: any) {
// dispatch(
// setAuthState({
// loading: false,
// data: null,
// error: error.response.data.errorMessage,
// })
// );
// }
// };
// const userData = await fetchUser();
// ---------------------------------------------------------------