diff --git a/src/App.tsx b/src/App.tsx
index ffba632..fa1f5f2 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -9,7 +9,11 @@ import AwardsView from './views/Award/AwardsView.tsx';
import ConsequencesView from './views/ConsequencesView';
import SettingsView from './views/SettingsView';
import Head from './Head';
-import { AWARDS_SUB_ROUTES, BASE_ROUTES_NAME, SUB_ROUTES_NAME } from './const/routing.const';
+import {
+ AWARDS_SUB_ROUTES,
+ BASE_ROUTES_NAME,
+ SUB_ROUTES_NAME,
+} from './const/routing.const';
import Login from './views/Login.tsx';
import AuthProvider from './providers/AuthProvider.tsx';
import AddAward from './views/Award/AddAward.tsx';
@@ -17,27 +21,37 @@ import GrantAward from './views/Award/GrantAward.tsx';
function App(): React.ReactNode {
return (
-
-
-
+
+
+
+
} />
} />
} />
- } />
- } />
-
+ }
+ />
+ }
+ />
+
}
/>
- } />
+ }
+ />
}
/>
- }
/>
@@ -47,8 +61,8 @@ function App(): React.ReactNode {
/>
-
-
+
+
);
}
diff --git a/src/components/atoms/Heading/Heading.ts b/src/components/atoms/Heading/Heading.ts
index 2cdf2d3..b7da1d5 100644
--- a/src/components/atoms/Heading/Heading.ts
+++ b/src/components/atoms/Heading/Heading.ts
@@ -3,18 +3,18 @@ import { ThemeTypes } from '../../../theme/appTheme';
interface HeadingPropsInterface {
theme: ThemeTypes;
- big?: boolean;
+ $big?: boolean;
}
export const Heading = styled.h1`
- font-size: ${({ theme, big }) =>
- big ? theme.fontSize.xl : theme.fontSize.lg};
+ font-size: ${({ theme, $big }) =>
+ $big ? theme.fontSize.xl : theme.fontSize.lg};
font-weight: ${({ theme }) => theme.bold};
margin: 0 0 10px;
@media only screen and (max-width: ${({ theme }) => theme.mediaMaxSize.xs}) {
- font-size: ${({ theme, big }) =>
- big ? theme.fontSize.md : theme.fontSize.sm};
+ font-size: ${({ theme, $big }) =>
+ $big ? theme.fontSize.md : theme.fontSize.sm};
}
`;
diff --git a/src/components/atoms/Paragraph/Paragraph.ts b/src/components/atoms/Paragraph/Paragraph.ts
index 9f9d05c..0c9e02a 100644
--- a/src/components/atoms/Paragraph/Paragraph.ts
+++ b/src/components/atoms/Paragraph/Paragraph.ts
@@ -3,17 +3,17 @@ import type { ThemeTypes } from '../../../theme/appTheme';
interface ParagraphInterface {
theme: ThemeTypes;
- big?: boolean;
+ $big?: boolean;
}
const Paragraph = styled.p`
- font-size: ${({ theme, big }) =>
- big ? theme.fontSize.md : theme.fontSize.sm};
+ font-size: ${({ theme, $big }) =>
+ $big ? theme.fontSize.md : theme.fontSize.sm};
margin: 0 0 10px;
@media only screen and (max-width: ${({ theme }) => theme.mediaMaxSize.xs}) {
- font-size: ${({ theme, big }) =>
- big ? theme.fontSize.sm : theme.fontSize.xs};
+ font-size: ${({ theme, $big }) =>
+ $big ? theme.fontSize.sm : theme.fontSize.xs};
}
`;
diff --git a/src/components/modules/StudentCard/StudentCard.tsx b/src/components/modules/StudentCard/StudentCard.tsx
index 3bbf5ad..07c4bc2 100644
--- a/src/components/modules/StudentCard/StudentCard.tsx
+++ b/src/components/modules/StudentCard/StudentCard.tsx
@@ -40,7 +40,7 @@ const StudentCard = ({ name, studentId, image }: PropTypesStudentCard) => {
return (
- {name}
+ {name}
);
};
diff --git a/src/constants.ts b/src/constants.ts
new file mode 100644
index 0000000..8a4a49f
--- /dev/null
+++ b/src/constants.ts
@@ -0,0 +1 @@
+export const localStorageKey = 'token';
diff --git a/src/providers/AuthProvider.tsx b/src/providers/AuthProvider.tsx
index 55b4873..e5e73e6 100644
--- a/src/providers/AuthProvider.tsx
+++ b/src/providers/AuthProvider.tsx
@@ -6,9 +6,10 @@ import {
authenticationReducer,
type AuthenticationReducer,
} from './authenticationReducer.ts';
+import { localStorageKey } from '../constants.ts';
export const AuthenticationContext = createContext({
- token: "",
+ token: '',
});
export const TokenDispatchContext = createContext>(
{} as React.Dispatch
@@ -18,14 +19,13 @@ export const useAuthenticationData = () => useContext(AuthenticationContext);
export const useTokenDispatch = () => useContext(TokenDispatchContext);
const AuthProvider = ({ children }: { children: React.ReactNode }) => {
- const localStorageKey = 'token';
const navigate = useNavigate();
const [authentication, dispatch] = useReducer(
authenticationReducer,
- {
- token: ""
- }
+ {
+ token: '',
+ }
);
useEffect(() => {
@@ -33,11 +33,17 @@ const AuthProvider = ({ children }: { children: React.ReactNode }) => {
axios.defaults.headers.common['Authorization'] =
'Bearer ' + authentication.token;
localStorage.setItem(localStorageKey, authentication.token);
+ console.log('Have token');
} else if (localStorage.getItem(localStorageKey)) {
+ console.log(localStorage.getItem(localStorageKey), 'token');
axios.defaults.headers.common['Authorization'] =
'Bearer ' + localStorage.getItem(localStorageKey);
+
+ console.log('going to local storage ');
} else {
navigate('/login');
+
+ console.log('redirecting');
}
}, [authentication, localStorageKey]);
diff --git a/src/providers/authenticationActions.ts b/src/providers/authenticationActions.ts
index b77f990..d9a7bc6 100644
--- a/src/providers/authenticationActions.ts
+++ b/src/providers/authenticationActions.ts
@@ -14,6 +14,6 @@ export const setToken = (
export const clearToken = (dispatch: React.Dispatch) => {
dispatch({
type: 'clear',
- token: null,
+ token: '',
});
};
diff --git a/src/providers/authenticationReducer.ts b/src/providers/authenticationReducer.ts
index 1e8dac1..f1aee09 100644
--- a/src/providers/authenticationReducer.ts
+++ b/src/providers/authenticationReducer.ts
@@ -1,4 +1,5 @@
import { type Authentication, type TokenAction } from './types.ts';
+import { localStorageKey } from '../constants.ts';
export type AuthenticationReducer = (
token: Authentication,
@@ -12,8 +13,10 @@ export const authenticationReducer: AuthenticationReducer = (
switch (action.type) {
case 'set':
return { token: action.token };
- case 'clear':
- return { token: "" };
+ case 'clear': {
+ localStorage.setItem(localStorageKey, '');
+ return { token: '' };
+ }
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Invalid action type ${action.type}`);
diff --git a/src/views/Login.tsx b/src/views/Login.tsx
index cb83c90..06ae3cc 100644
--- a/src/views/Login.tsx
+++ b/src/views/Login.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Heading } from '../components/atoms/Heading/Heading.ts';
import MainBox from '../components/atoms/Sections/MainBox.ts';
@@ -12,7 +12,7 @@ import { type User } from '../api/Authentication/userTypes.ts';
import Button from '../components/atoms/Buttons/Button.ts';
import useAuthenticateUser from '../api/Authentication/authenticateUser.ts';
import { useTokenDispatch } from '../providers/AuthProvider.tsx';
-import { setToken } from '../providers/authenticationActions.ts';
+import { clearToken, setToken } from '../providers/authenticationActions.ts';
const Login = () => {
const [formData, setFormData] = useState({
@@ -25,9 +25,13 @@ const Login = () => {
const { trigger, isMutating, error } = useAuthenticateUser();
const navigate = useNavigate();
- const handleSubmit = async (
- event: React.MouseEvent
- ) => {
+ useEffect(() => {
+ clearToken(dispatch);
+
+ console.log();
+ }, []);
+
+ const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
const response = await trigger({
username: formData.userName,
@@ -42,13 +46,12 @@ const Login = () => {
Zaloguj się
- handleSubmit}>
+
Nazwa użytkownika:
setFormData({ ...formData, userName: event.target.value })
}
@@ -56,21 +59,16 @@ const Login = () => {
/>
Hasło:
setFormData({ ...formData, password: event.target.value })
}
required
/>
{error && Błąd logowania. Spróbuj ponownie.
}
-