=> handle(axiosInstance.delete(uri, settings))
}
- if (sessionStorage.getItem('token')) api.profile().finally(() => {})
-
return api
})()
diff --git a/src/core/repositories/security-repository.js b/src/core/repositories/security-repository.js
index fd0e3bb..0dbaf44 100644
--- a/src/core/repositories/security-repository.js
+++ b/src/core/repositories/security-repository.js
@@ -16,18 +16,18 @@ const SecurityRepository = (api => {
sessionStorage.setItem('refresh-token', token.refreshToken);
sessionStorage.setItem('token', token.accessToken);
}),
+ twoFactor: (code) => api.post('security/2-factor', { verificationCode: code })
+ .then(serverResponse => {
+ const token = new TokenResponse(serverResponse)
+ sessionStorage.setItem('refresh-token', token.refreshToken);
+ sessionStorage.setItem('token', token.accessToken);
+ }),
register: (username, password) => api.put(`security/create-account`, { username, password }),
logout: () => {
- sessionStorage.removeItem('token');
- sessionStorage.removeItem('refresh-token');
- }
+ sessionStorage.removeItem('token');
+ sessionStorage.removeItem('refresh-token');
+ }
}
})(RestAPI)
-window.addEventListener('credentials-expired', _ => {
- console.log('Credentials expired')
- SecurityRepository.logout()
- window.location.reload()
-})
-
export default SecurityRepository
\ No newline at end of file
diff --git a/src/core/sidebar/index.tsx b/src/core/sidebar/index.tsx
index 58fc099..57b43b8 100644
--- a/src/core/sidebar/index.tsx
+++ b/src/core/sidebar/index.tsx
@@ -16,11 +16,6 @@ type SidebarProps = {
}
const Sidebar = ({ logoutCallback } : SidebarProps) => {
- const onLogout = () => {
- dispatchEvent(new CustomEvent('credentials-expired'))
- logoutCallback()
- }
-
return <>
diff --git a/src/core/sidebar/mobile-sidebar.tsx b/src/core/sidebar/mobile-sidebar.tsx
index 0076b30..27da6c0 100644
--- a/src/core/sidebar/mobile-sidebar.tsx
+++ b/src/core/sidebar/mobile-sidebar.tsx
@@ -8,7 +8,6 @@ import { NavLink } from "react-router-dom";
import ProfilePicture from "../../profile/profile-picture.component";
import { Buttons } from "../index";
import { mdiCloseBox, mdiLogoutVariant } from "@mdi/js";
-import SecurityRepository from "../repositories/security-repository";
type SidebarProps = {
@@ -17,10 +16,6 @@ type SidebarProps = {
const MobileSidebar = ({ logoutCallback } : SidebarProps) => {
const [isOpen, setIsOpen] = useState(false)
- const onLogout = () => {
- SecurityRepository.logout()
- logoutCallback()
- }
useEffect(() => {
const onMenuClick = () => setIsOpen(previous => !previous)
@@ -61,7 +56,7 @@ const MobileSidebar = ({ logoutCallback } : SidebarProps) => {
className='border-none !text-white' />
diff --git a/src/security/login-card.tsx b/src/security/login-card.tsx
index d729365..f9ae3b0 100644
--- a/src/security/login-card.tsx
+++ b/src/security/login-card.tsx
@@ -1,5 +1,4 @@
import React, { useState } from "react";
-import { useNavigate } from "react-router-dom";
import { mdiAccountPlus, mdiLogin, mdiWeb } from "@mdi/js";
import { Form, Input, SubmitButton } from '../core/form'
@@ -16,11 +15,9 @@ type LoginCallback = () => void
const LoginCard = ({ callback }: { callback: LoginCallback }) => {
const [failure, setFailure] = useState()
- const navigate = useNavigate()
const onSubmit = (entity: LoginForm) => SecurityRepository.authenticate(entity.username, entity.password)
.then(() => callback())
- .then(() => navigate('/dashboard'))
.catch(setFailure)
return (
diff --git a/src/security/two-factor.card.tsx b/src/security/two-factor.card.tsx
new file mode 100644
index 0000000..853000c
--- /dev/null
+++ b/src/security/two-factor.card.tsx
@@ -0,0 +1,39 @@
+import { Form, Input, SubmitButton } from "../core/form";
+import { Layout, Message, Notifications } from "../core";
+import { mdiCheck } from "@mdi/js";
+import SecurityRepository from "../core/repositories/security-repository";
+import { AxiosError } from "axios";
+
+const TwoFactorCard = ({ callback }: { callback: () => void }) => {
+ const onSubmit = (entity: any) => {
+ SecurityRepository.twoFactor(entity.code)
+ .then(callback)
+ .catch((error: AxiosError) => Notifications.Service.exception(error))
+ }
+
+ return <>
+
+
+
+ >
+}
+
+export default TwoFactorCard;
\ No newline at end of file