mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 09:35:36 +01:00
Add OIDC authentification in project
This commit is contained in:
parent
777515f754
commit
fa2c915fe1
16 changed files with 545 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
PasswordField,
|
||||
SubmitButton,
|
||||
Icon,
|
||||
Button,
|
||||
} from 'react-basics';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useApi, useMessages } from '@/components/hooks';
|
||||
|
|
@ -16,12 +17,24 @@ import Logo from '@/assets/logo.svg';
|
|||
import styles from './LoginForm.module.css';
|
||||
|
||||
export function LoginForm() {
|
||||
const { formatMessage, labels, getMessage } = useMessages();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const router = useRouter();
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error, isPending } = useMutation({
|
||||
mutationFn: (data: any) => post('/auth/login', data),
|
||||
});
|
||||
const { mutate: startOIDC, isPending: isOIDC } = useMutation({
|
||||
mutationFn: async (returnUrl?: string) => {
|
||||
const res = await fetch(
|
||||
`/api/auth/oidc/authorize?returnUrl=${encodeURIComponent(returnUrl || '/dashboard')}`,
|
||||
);
|
||||
const data = await res.json();
|
||||
if (data?.url) {
|
||||
window.location.href = data.url;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
mutate(data, {
|
||||
|
|
@ -40,7 +53,7 @@ export function LoginForm() {
|
|||
<Logo />
|
||||
</Icon>
|
||||
<div className={styles.title}>umami</div>
|
||||
<Form className={styles.form} onSubmit={handleSubmit} error={getMessage(error)}>
|
||||
<Form className={styles.form} onSubmit={handleSubmit} error={error}>
|
||||
<FormRow label={formatMessage(labels.username)}>
|
||||
<FormInput
|
||||
data-test="input-username"
|
||||
|
|
@ -68,6 +81,14 @@ export function LoginForm() {
|
|||
>
|
||||
{formatMessage(labels.login)}
|
||||
</SubmitButton>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => startOIDC('/dashboard')}
|
||||
disabled={isOIDC}
|
||||
className={styles.button}
|
||||
>
|
||||
Se connecter avec OIDC
|
||||
</Button>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue