frontend/src/components/AuthData.tsx   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 41
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 41
ccs 4
cts 9
cp 0.4444
rs 10
c 0
b 0
f 0
wmc 3
mnd 2
bc 2
fnc 1
bpm 2
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A AuthData.tsx ➔ AuthData 0 33 3
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