From f8095c7ec6b0e2322b9351fa4f0a1a61ffc49b60 Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 1 Dec 2022 16:27:56 +0100 Subject: [PATCH] oops i did some work directly on master, but it's still stable so should be fine --- .../src/auth/42/authentication.controller.ts | 7 +++- .../src/pages/TwoFactorAuthentication.svelte | 2 + .../api_front/src/routes/primaryRoutes.js | 38 +++++++++---------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/srcs/requirements/nestjs/api_back/src/auth/42/authentication.controller.ts b/srcs/requirements/nestjs/api_back/src/auth/42/authentication.controller.ts index 08661276..94b955bb 100644 --- a/srcs/requirements/nestjs/api_back/src/auth/42/authentication.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/auth/42/authentication.controller.ts @@ -34,7 +34,7 @@ export class AuthenticationController { console.log('ON EST DANS REDIRECT AUTH CONTROLLER'); console.log('On redirige'); if (request.user.isEnabledTwoFactorAuth === false) - return response.status(200).redirect('http://transcendance:8080/'); + return response.status(200).redirect('http://transcendance:8080/#/profile'); return response.status(200).redirect('http://transcendance:8080/#/2fa'); } @@ -74,6 +74,9 @@ export class AuthenticationController { } await this.userService.enableTwoFactorAuth(request.user.id); console.log('ON REDIRIGE'); - return response.status(200); + // return response.status(200); + // return 200; + // needs to be looked at by Cherif + return response.status(200).redirect('http://transcendance:8080/'); } } diff --git a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte index ab48e223..8fc8d500 100644 --- a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte @@ -19,6 +19,7 @@ let qrCodeImg; let qrCode = ""; let wrongCode = ""; + // max try doesn't work if you reste the page let maxTry = 3; const fetchQrCodeImg = (async() => { await fetch("http://transcendance:8080/api/v2/auth/2fa/generate", @@ -61,6 +62,7 @@ if (response.status === 200) { // loginStatus.toggleTFA(); loginStatus.update( (old) => ({...old, tfa: true}) ); + // push('/profile'); console.log('vaid Code for 2FA') } diff --git a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js index de8e6d3c..fd9ba911 100644 --- a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js @@ -60,32 +60,32 @@ import { get } from 'svelte/store'; // } // ] // }), - // and example // '/profile': wrap({ - // // Use a dynamically-loaded component for this - // asyncComponent: () => import('./ProfilePage.svelte'), - // // Adding one pre-condition that's an async function - // conditions: [ - // async (detail) => { - // // Make a network request, which are async operations - // const response = await fetch('http://transcendance:8080/api/v2/user') - // const data = await response.json() - // // Return true to continue loading the component, or false otherwise - // if (data.isAdmin) { - // return true - // } - // else { - // return false - // } - // } - // ] - // }), +// // Use a dynamically-loaded component for this +// asyncComponent: () => import('./ProfilePage.svelte'), +// // Adding one pre-condition that's an async function +// conditions: [ +// async (detail) => { +// // Make a network request, which are async operations +// const response = await fetch('http://transcendance:8080/api/v2/user') +// const data = await response.json() +// // Return true to continue loading the component, or false otherwise +// if (data.isAdmin) { +// return true +// } +// else { +// return false +// } +// } +// ] +// }), // '/unauthorized-access': UnauthorizedAccessPage, // '*': NotFound // }; export const primaryRoutes = { "/": SplashPage, + '/2fa': TwoFactorAuthentication, "/profile": ProfilePage, "/profile/*": ProfilePage, '/unauthorized-access': UnauthorizedAccessPage,