mirror of
https://github.com/diced/zipline.git
synced 2026-04-28 10:43:06 -07:00
fix: add register link on login page
other minor fixes as well incl.
This commit is contained in:
@@ -33,7 +33,7 @@ import {
|
||||
IconCircleKeyFilled,
|
||||
} from '@tabler/icons-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import useSWR from 'swr';
|
||||
import GenericError from '../../error/GenericError';
|
||||
import { eitherTrue } from '@/lib/primitive';
|
||||
@@ -43,7 +43,11 @@ export default function Login() {
|
||||
|
||||
const query = new URLSearchParams(location.search);
|
||||
const navigate = useNavigate();
|
||||
const { user, mutate } = useLogin();
|
||||
const { user, mutate } = useLogin({
|
||||
swrConfig: {
|
||||
shouldRetryOnError: false
|
||||
},
|
||||
});
|
||||
|
||||
const isHttps = window.location.protocol === 'https:';
|
||||
const webClient = JSON.stringify(getWebClient());
|
||||
@@ -212,6 +216,7 @@ export default function Login() {
|
||||
config.oauthEnabled.github,
|
||||
config.oauthEnabled.google,
|
||||
config.oauthEnabled.oidc,
|
||||
config.features.userRegistration,
|
||||
) && (
|
||||
<>
|
||||
<Divider label='or' />
|
||||
@@ -243,6 +248,15 @@ export default function Login() {
|
||||
<ExternalAuthButton provider='OIDC' leftSection={<IconCircleKeyFilled size='1.1rem' />} />
|
||||
)}
|
||||
</Group>
|
||||
|
||||
{config.features.userRegistration && (
|
||||
<Text ta='center' mt='md'>
|
||||
Don't have an account?{' '}
|
||||
<Anchor component={Link} to='/auth/register' c='blue' fw={500}>
|
||||
Register
|
||||
</Anchor>
|
||||
</Text>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@@ -299,10 +299,11 @@ export default function DashboardServerSettings() {
|
||||
{(data?.tampered?.length ?? 0) > 0 && (
|
||||
<Collapse expanded={opened} transitionDuration={180}>
|
||||
<Alert
|
||||
my='md'
|
||||
color='red'
|
||||
title='Environment Variable Settings'
|
||||
mb='md'
|
||||
icon={<IconExclamationMark size='1rem' />}
|
||||
variant='outline'
|
||||
>
|
||||
<Text size='sm' mb='xs'>
|
||||
These settings are controlled by environment variables:
|
||||
|
||||
@@ -125,6 +125,7 @@ export default function UploadText() {
|
||||
disabled={loading}
|
||||
className={styles.textarea}
|
||||
my='sm'
|
||||
resize='vertical'
|
||||
/>
|
||||
|
||||
<Group style={{ position: 'absolute', bottom: 10, right: 10 }} gap='xs'>
|
||||
|
||||
@@ -2,13 +2,19 @@ import type { Response } from '@/lib/api/response';
|
||||
import { isAdministrator } from '@/lib/role';
|
||||
import { useEffect } from 'react';
|
||||
import { redirect } from 'react-router-dom';
|
||||
import useSWR from 'swr';
|
||||
import useSWR, { SWRConfiguration } from 'swr';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useUserStore } from '../store/user';
|
||||
|
||||
export default function useLogin(administratorOnly: boolean = false) {
|
||||
export default function useLogin(
|
||||
{ admin, swrConfig: swrOptions }: { admin?: boolean; swrConfig?: SWRConfiguration } = {
|
||||
admin: false,
|
||||
swrConfig: {},
|
||||
},
|
||||
) {
|
||||
const { data, error, isLoading, mutate } = useSWR<Response['/api/user']>('/api/user', {
|
||||
fallbackData: { user: undefined },
|
||||
...swrOptions,
|
||||
});
|
||||
|
||||
const [user, setUser] = useUserStore(useShallow((state) => [state.user, state.setUser]));
|
||||
@@ -22,7 +28,7 @@ export default function useLogin(administratorOnly: boolean = false) {
|
||||
}, [data, error]);
|
||||
|
||||
useEffect(() => {
|
||||
if (user && administratorOnly && !isAdministrator(user.role)) {
|
||||
if (user && admin && !isAdministrator(user.role)) {
|
||||
redirect('/dashboard');
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
Reference in New Issue
Block a user