From db578dbe517cf716a2a06763e51dc1f44adb247f Mon Sep 17 00:00:00 2001 From: Sonny Date: Tue, 5 Nov 2024 22:27:17 +0100 Subject: [PATCH] feat: remove login page (temp) --- app/controllers/users_controller.ts | 4 +- app/middleware/auth_middleware.ts | 2 +- .../components/common/mantine_user_card.tsx | 7 +- inertia/components/navbar/mantine_navbar.tsx | 8 +- inertia/components/navbar/navbar.tsx | 2 +- inertia/i18n/index.ts | 9 +- inertia/i18n/locales/en/login.json | 6 -- inertia/i18n/locales/fr/login.json | 6 -- inertia/pages/login.tsx | 92 ------------------- start/routes/auth.ts | 3 +- 10 files changed, 17 insertions(+), 122 deletions(-) delete mode 100644 inertia/i18n/locales/en/login.json delete mode 100644 inertia/i18n/locales/fr/login.json delete mode 100644 inertia/pages/login.tsx diff --git a/app/controllers/users_controller.ts b/app/controllers/users_controller.ts index c8df55f..227a460 100644 --- a/app/controllers/users_controller.ts +++ b/app/controllers/users_controller.ts @@ -5,7 +5,7 @@ import db from '@adonisjs/lucid/services/db'; import { RouteName } from '@izzyjs/route/types'; export default class UsersController { - private redirectTo: RouteName = 'auth.login'; + private redirectTo: RouteName = 'auth'; login({ inertia }: HttpContext) { return inertia.render('login'); @@ -67,7 +67,7 @@ export default class UsersController { await auth.use('web').logout(); session.flash('flash', 'Successfully disconnected'); logger.info(`[${auth.user?.email}] disconnected successfully`); - response.redirectToNamedRoute(this.redirectTo); + response.redirect('/'); } async getAllUsersWithTotalRelations() { diff --git a/app/middleware/auth_middleware.ts b/app/middleware/auth_middleware.ts index afb149e..9332846 100644 --- a/app/middleware/auth_middleware.ts +++ b/app/middleware/auth_middleware.ts @@ -11,7 +11,7 @@ export default class AuthMiddleware { /** * The URL to redirect to, when authentication fails */ - redirectTo = route('auth.login').url; + redirectTo = route('auth').path; async handle( ctx: HttpContext, diff --git a/inertia/components/common/mantine_user_card.tsx b/inertia/components/common/mantine_user_card.tsx index 666ff0c..920fe90 100644 --- a/inertia/components/common/mantine_user_card.tsx +++ b/inertia/components/common/mantine_user_card.tsx @@ -1,5 +1,7 @@ +import { route } from '@izzyjs/route/client'; import { Avatar, Group, Menu, Text, UnstyledButton } from '@mantine/core'; import { forwardRef } from 'react'; +import { useTranslation } from 'react-i18next'; import { TbChevronRight } from 'react-icons/tb'; import useUser from '~/hooks/use_user'; @@ -44,6 +46,7 @@ const UserButton = forwardRef( ); export function MantineUserCard() { + const { t } = useTranslation('common'); const { user, isAuthenticated } = useUser(); return ( isAuthenticated && ( @@ -56,7 +59,9 @@ export function MantineUserCard() { /> - Logout + + {t('logout')} + ) diff --git a/inertia/components/navbar/mantine_navbar.tsx b/inertia/components/navbar/mantine_navbar.tsx index 10581da..a73b54a 100644 --- a/inertia/components/navbar/mantine_navbar.tsx +++ b/inertia/components/navbar/mantine_navbar.tsx @@ -50,8 +50,8 @@ export default function MantineNavbar() { {!isAuthenticated ? ( ) : ( diff --git a/inertia/components/navbar/navbar.tsx b/inertia/components/navbar/navbar.tsx index 087067d..5b97858 100644 --- a/inertia/components/navbar/navbar.tsx +++ b/inertia/components/navbar/navbar.tsx @@ -97,7 +97,7 @@ export default function Navbar() {
  • - {t('login')} + {t('login')}
  • )} diff --git a/inertia/i18n/index.ts b/inertia/i18n/index.ts index aa7e3b8..ecda045 100644 --- a/inertia/i18n/index.ts +++ b/inertia/i18n/index.ts @@ -8,29 +8,26 @@ import frResourceAbout from './locales/fr/about.json'; import frResourceAdmin from './locales/fr/admin.json'; import frResourceCommon from './locales/fr/common.json'; import frResourceHome from './locales/fr/home.json'; -import frResourceLogin from './locales/fr/login.json'; +import frResourceLegal from './locales/fr/legal.json'; import frResourcePrivacy from './locales/fr/privacy.json'; import frResourceTerms from './locales/fr/terms.json'; -import frResourceLegal from './locales/fr/legal.json'; import { LS_LANG_KEY } from '~/constants'; import enResourceAbout from './locales/en/about.json'; import enResourceAdmin from './locales/en/admin.json'; import enResourceCommon from './locales/en/common.json'; import enResourceHome from './locales/en/home.json'; -import enResourceLogin from './locales/en/login.json'; +import enResourceLegal from './locales/en/legal.json'; import enResourcePrivacy from './locales/en/privacy.json'; import enResourceTerms from './locales/en/terms.json'; -import enResourceLegal from './locales/en/legal.json'; type I18nFR = | RemoveSuffix> | RemoveSuffix> | RemoveSuffix> | RemoveSuffix> - | RemoveSuffix> | RemoveSuffix> | RemoveSuffix> | RemoveSuffix>; @@ -42,7 +39,6 @@ export const resources = { admin: enResourceAdmin, common: enResourceCommon, home: enResourceHome, - login: enResourceLogin, privacy: enResourcePrivacy, terms: enResourceTerms, legal: enResourceLegal, @@ -52,7 +48,6 @@ export const resources = { admin: frResourceAdmin, common: frResourceCommon, home: frResourceHome, - login: frResourceLogin, privacy: frResourcePrivacy, terms: frResourceTerms, legal: frResourceLegal, diff --git a/inertia/i18n/locales/en/login.json b/inertia/i18n/locales/en/login.json deleted file mode 100644 index 41c3e1e..0000000 --- a/inertia/i18n/locales/en/login.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "title": "Authentication", - "informative-text": "Authentication required to use MyLinks", - "continue-with": "Continue with {{provider}}", - "accept-terms": "By continuing, you accept the" -} diff --git a/inertia/i18n/locales/fr/login.json b/inertia/i18n/locales/fr/login.json deleted file mode 100644 index 2ae2260..0000000 --- a/inertia/i18n/locales/fr/login.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "title": "Authentification", - "informative-text": "Authentification requise pour utiliser MyLinks", - "continue-with": "Continuer avec {{provider}}", - "accept-terms": "En poursuivant, vous acceptez les" -} diff --git a/inertia/pages/login.tsx b/inertia/pages/login.tsx deleted file mode 100644 index ee43d55..0000000 --- a/inertia/pages/login.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import styled from '@emotion/styled'; -import { Head, Link } from '@inertiajs/react'; -import { route } from '@izzyjs/route/client'; -import { ReactNode } from 'react'; -import { useTranslation } from 'react-i18next'; -import { FcGoogle } from 'react-icons/fc'; -import Button from '~/components/common/form/_button'; -import ContentLayout from '~/components/layouts/content_layout'; -import Quotes from '~/components/quotes'; - -const LoginContainer = styled.div({ - width: '100%', - maxWidth: '100%', - whiteSpace: 'nowrap', - marginTop: '50px', - paddingInline: '1rem', - display: 'flex', - alignItems: 'center', - gap: '1.5em', - flexDirection: 'column', -}); - -const FormWrapper = styled.div(({ theme }) => ({ - width: '500px', - maxWidth: '100%', - backgroundColor: theme.colors.secondary, - padding: '2em', - borderRadius: theme.border.radius, - border: `1px solid ${theme.colors.lightGrey}`, - display: 'flex', - gap: '1em', - flex: 1, - alignItems: 'center', - justifyContent: 'center', - flexDirection: 'column', -})); - -const InformativeText = styled.p(({ theme }) => ({ - width: '100%', - padding: '10px', - textAlign: 'center', - color: theme.colors.darkBlue, - backgroundColor: theme.colors.lightestBlue, - borderRadius: theme.border.radius, -})); - -const AgreementText = styled.p(({ theme }) => ({ - color: theme.colors.grey, -})); - -const ButtonLink = styled(Button.withComponent('a'))({ - display: 'flex', - gap: '0.35em', - alignItems: 'center', - justifyContent: 'center', -}); - -function LoginPage() { - const { t } = useTranslation(); - return ( - - - MyLinks's logo - {t('common:slogan')} - -

    {t('login:title')}

    - {t('login:informative-text')} - - {' '} - {t('login:continue-with', { provider: 'Google' })} - -
    - - {t('login:accept-terms')}{' '} - {t('common:terms')} - -
    - ); -} - -LoginPage.layout = (page: ReactNode) => ( - -); -export default LoginPage; diff --git a/start/routes/auth.ts b/start/routes/auth.ts index e097ed4..a33f01f 100644 --- a/start/routes/auth.ts +++ b/start/routes/auth.ts @@ -9,8 +9,7 @@ const ROUTES_PREFIX = '/auth'; */ router .group(() => { - router.get('/login', [UsersController, 'login']).as('auth.login'); - router.get('/google', [UsersController, 'google']).as('auth.google'); + router.get('/google', [UsersController, 'google']).as('auth'); router .get('/callback', [UsersController, 'callbackAuth']) .as('auth.callback');