2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

make login/register seperate paths

This commit is contained in:
Matthias Mair
2025-01-20 21:52:24 +01:00
parent 6bad3ff2ff
commit 0c40cb4a5a
3 changed files with 17 additions and 5 deletions

View File

@ -332,10 +332,10 @@ export function RegistrationForm() {
export function ModeSelector({ export function ModeSelector({
loginMode, loginMode,
setMode changePage
}: Readonly<{ }: Readonly<{
loginMode: boolean; loginMode: boolean;
setMode: any; changePage: (state: string) => void;
}>) { }>) {
const [sso_registration, registration_enabled] = useServerApiState( const [sso_registration, registration_enabled] = useServerApiState(
(state) => [state.sso_registration_enabled, state.registration_enabled] (state) => [state.sso_registration_enabled, state.registration_enabled]
@ -354,7 +354,7 @@ export function ModeSelector({
type='button' type='button'
c='dimmed' c='dimmed'
size='xs' size='xs'
onClick={() => setMode.close()} onClick={() => changePage('register')}
> >
<Trans>Register</Trans> <Trans>Register</Trans>
</Anchor> </Anchor>
@ -365,7 +365,7 @@ export function ModeSelector({
type='button' type='button'
c='dimmed' c='dimmed'
size='xs' size='xs'
onClick={() => setMode.open()} onClick={() => changePage('login')}
> >
<Trans>Go back to login</Trans> <Trans>Go back to login</Trans>
</Anchor> </Anchor>

View File

@ -39,6 +39,14 @@ export default function Login() {
const location = useLocation(); const location = useLocation();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
useEffect(() => {
if (location.pathname === '/register') {
setMode.close();
} else {
setMode.open();
}
}, [location]);
// Data manipulation functions // Data manipulation functions
function ChangeHost(newHost: string | null): void { function ChangeHost(newHost: string | null): void {
if (newHost === null) return; if (newHost === null) return;
@ -95,7 +103,10 @@ export default function Login() {
)} )}
</Text> </Text>
{loginMode ? <AuthenticationForm /> : <RegistrationForm />} {loginMode ? <AuthenticationForm /> : <RegistrationForm />}
<ModeSelector loginMode={loginMode} setMode={setMode} /> <ModeSelector
loginMode={loginMode}
changePage={(newPage) => navigate(`/${newPage}`)}
/>
</Paper> </Paper>
<AuthFormOptions hostname={hostname} toggleHostEdit={setHostEdit} /> <AuthFormOptions hostname={hostname} toggleHostEdit={setHostEdit} />
</> </>

View File

@ -171,6 +171,7 @@ export const routes = (
</Route> </Route>
<Route path='/' errorElement={<ErrorPage />}> <Route path='/' errorElement={<ErrorPage />}>
<Route path='/login' element={<Login />} />, <Route path='/login' element={<Login />} />,
<Route path='/register' element={<Login />} />,
<Route path='/mfa' element={<MFALogin />} />, <Route path='/mfa' element={<MFALogin />} />,
<Route path='/logout' element={<Logout />} />, <Route path='/logout' element={<Logout />} />,
<Route path='/logged-in' element={<Logged_In />} /> <Route path='/logged-in' element={<Logged_In />} />