oidc authentication
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
import { toTypedSchema } from '@vee-validate/yup';
|
||||
import { useForm } from 'vee-validate';
|
||||
import { loginUser } from '~/lib/api/auth/login';
|
||||
import { getRedirectUrl, oidcLoginUser } from '~/lib/api/auth/oidc';
|
||||
import { loginSchema } from '~/lib/schemas/auth';
|
||||
|
||||
definePageMeta({
|
||||
@@ -20,10 +21,31 @@ useHead({
|
||||
title: 'Login - Warren',
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
// TODO: Get this from the backend
|
||||
const OPEN_ID = false;
|
||||
const OPEN_ID = true;
|
||||
const loggingIn = ref(false);
|
||||
|
||||
if (
|
||||
route.query.code &&
|
||||
typeof route.query.code === 'string' &&
|
||||
route.query.state &&
|
||||
typeof route.query.state === 'string'
|
||||
) {
|
||||
console.log('SEND');
|
||||
loggingIn.value = true;
|
||||
const { success } = await oidcLoginUser(
|
||||
route.query.code,
|
||||
route.query.state
|
||||
);
|
||||
loggingIn.value = false;
|
||||
|
||||
if (success) {
|
||||
await navigateTo({ path: '/' });
|
||||
}
|
||||
}
|
||||
|
||||
const form = useForm({
|
||||
validationSchema: toTypedSchema(loginSchema),
|
||||
});
|
||||
@@ -43,6 +65,24 @@ const onSubmit = form.handleSubmit(async (values) => {
|
||||
|
||||
loggingIn.value = false;
|
||||
});
|
||||
|
||||
async function oidcClicked() {
|
||||
if (loggingIn.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
loggingIn.value = true;
|
||||
|
||||
const result = await getRedirectUrl();
|
||||
|
||||
if (result.success) {
|
||||
await navigateTo(result.url, {
|
||||
external: true,
|
||||
});
|
||||
} else {
|
||||
loggingIn.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -97,7 +137,11 @@ const onSubmit = form.handleSubmit(async (values) => {
|
||||
:disabled="loggingIn"
|
||||
>Log in</Button
|
||||
>
|
||||
<Button class="w-full" variant="outline" :disabled="!OPEN_ID"
|
||||
<Button
|
||||
class="w-full"
|
||||
variant="outline"
|
||||
:disabled="!OPEN_ID || loggingIn"
|
||||
@click="oidcClicked"
|
||||
>OpenID Connect</Button
|
||||
>
|
||||
<NuxtLink to="/register" class="w-full">
|
||||
|
||||
Reference in New Issue
Block a user