1
|
|
|
import { useSelector } from 'react-redux'; |
2
|
|
|
import { RootState } from '../redux/store/store'; |
3
|
|
|
import axios from 'axios'; |
4
|
|
|
import { API_URL, getHeader } from '../helpers/config'; |
5
|
|
|
import { Button, Popover } from "flowbite-react"; |
6
|
|
|
|
7
|
|
|
export default function AuthData() { |
8
|
|
|
|
9
|
4 |
|
const {isLoggedIn, token, user, role} = useSelector((state: RootState) => state.auth); |
10
|
|
|
|
11
|
2 |
|
const getAuthStatus = async () => { |
12
|
|
|
const response = await axios.get(`${API_URL}/auth/status`, getHeader(token)); |
13
|
|
|
console.log(response); |
14
|
|
|
} |
15
|
|
|
|
16
|
2 |
|
const getAuthMe = async () => { |
17
|
|
|
const response = await axios.get(`${API_URL}/auth/me`, getHeader(token)); |
18
|
|
|
console.log(response); |
19
|
|
|
} |
20
|
|
|
|
21
|
2 |
|
return ( |
22
|
|
|
<div className='w-full grid mb-10 text-center |
23
|
|
|
bg-red-100 grid-cols-2 text-xs max-w-lg p-2 |
24
|
|
|
mx-6 border border-gray-200 rounded-lg shadow' data-testid="authdata"> |
25
|
|
|
<div className="my-auto"> |
26
|
|
|
<p className="text-gray-700 m-1">Logged In: <b>{isLoggedIn.toString()}</b></p> |
27
|
|
|
<p className="text-gray-700 m-1">Role: <b>{role}</b></p> |
28
|
|
|
<p className="text-gray-700 m-1">User: <b>{user ? JSON.stringify(user) : "No User"}</b></p> |
29
|
|
|
</div> |
30
|
|
|
<div> |
31
|
|
|
<Popover aria-labelledby="default-popover" content={<p>{token ? token : "Empty"} </p>}> |
32
|
|
|
<Button color="gray" className="p-0 m-1" size="xs" onClick={() => console.log(token)}>Klicka här för token</Button> |
33
|
|
|
</Popover> |
34
|
|
|
|
35
|
|
|
<Button color="gray" className="p-0 m-1" size="xs" onClick={getAuthStatus}>Prompt auth/status i console</Button> |
36
|
|
|
<Button color="gray" className="p-0 m-1" size="xs" onClick={getAuthMe}>Prompt auth/me i console</Button> |
37
|
|
|
</div> |
38
|
|
|
</div> |
39
|
|
|
) |
40
|
|
|
}; |
41
|
|
|
|