login: add alert when login required

This commit is contained in:
axolotle 2023-11-30 15:58:10 +01:00
parent 3036186826
commit 73488092c4
6 changed files with 30 additions and 14 deletions

View file

@ -28,7 +28,7 @@ const classVariant = computed(() => {
<div <div
:aria-live="assertive ? 'assertive' : 'polite'" :aria-live="assertive ? 'assertive' : 'polite'"
aria-atomic="true" aria-atomic="true"
:class="'mt-8 alert ' + classVariant" :class="'alert ' + classVariant"
> >
<YIcon v-if="icon" :name="icon" size="2em" aria-hidden="true" /> <YIcon v-if="icon" :name="icon" size="2em" aria-hidden="true" />
<slot name="default"> <slot name="default">

View file

@ -46,7 +46,7 @@ provide(formGroupExtras, {
<div <div
role="group" role="group"
:aria-invalid="invalid" :aria-invalid="invalid"
:class="{ 'is-invalid': invalid, 'flex-col': !row }" :class="{ 'is-invalid': invalid, 'flex-col': !row, 'items-center': row }"
class="flex" class="flex"
> >
<slot name="label"> <slot name="label">
@ -54,15 +54,15 @@ provide(formGroupExtras, {
<label <label
:id="name + '__label'" :id="name + '__label'"
:for="name" :for="name"
class="block ms-1 mb-2" class="block ms-1"
:class="{ 'sr-only': srHideLabel, 'flex mb-0': !!icon }" :class="{ 'sr-only': srHideLabel, flex: !!icon, 'mb-2': !icon }"
> >
<YIcon <YIcon
v-if="icon" v-if="icon"
:name="icon" :name="icon"
aria-hidden="true" aria-hidden="true"
size="2em" size="2em"
class="m-2" class="me-2"
/> />
<span :class="{ 'sr-only': !!icon }">{{ label }}</span> <span :class="{ 'sr-only': !!icon }">{{ label }}</span>
</label> </label>

View file

@ -19,7 +19,7 @@ withDefaults(
<slot name="default" /> <slot name="default" />
<!-- Success + generic error announcement --> <!-- Success + generic error announcement -->
<BaseAlert v-show="feedback" v-bind="feedback" class="mb-8" /> <BaseAlert v-show="feedback" v-bind="feedback" class="my-8" />
<!-- SR "loading" announcement --> <!-- SR "loading" announcement -->
<BaseAlert <BaseAlert

View file

@ -48,6 +48,9 @@
"main_content": "Skip to main content", "main_content": "Skip to main content",
"footer": "Skip to footer" "footer": "Skip to footer"
}, },
"ssowat": {
"protected": "Please log in to access this url."
},
"theme": "Theme", "theme": "Theme",
"user_profile_updated": "User personal information updated with success!", "user_profile_updated": "User personal information updated with success!",
"username": "Username", "username": "Username",

View file

@ -8,9 +8,14 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
const isLoggedIn = useIsLoggedIn() const isLoggedIn = useIsLoggedIn()
const settings = await useSettings() const settings = await useSettings()
useRedirectUrl().value = (from.query.r as string) || null const redirectUrl = useRedirectUrl()
if (useRedirectUrl().value && to.name === 'login') { if (to.query.r) {
to.query.r = useRedirectUrl().value redirectUrl.value = to.query.r as string
if (to.name !== 'login') {
return navigateTo({ path: '/login', query: { r: to.query.r } })
}
} else {
redirectUrl.value = null
} }
if (to.name === 'login') { if (to.name === 'login') {

View file

@ -15,6 +15,7 @@ useHead({
}) })
const isLoggedIn = useIsLoggedIn() const isLoggedIn = useIsLoggedIn()
const redirectUrl = useRedirectUrl()
const { handleSubmit, setErrors } = useForm({ const { handleSubmit, setErrors } = useForm({
validationSchema: toTypedSchema( validationSchema: toTypedSchema(
@ -32,10 +33,8 @@ const login = handleSubmit(async (form) => {
}) })
if (!error.value) { if (!error.value) {
const redirectUrl = useRedirectUrl().value if (redirectUrl.value) {
await navigateTo(atob(redirectUrl.value), { external: true })
if (redirectUrl) {
await navigateTo(atob(redirectUrl), { external: true })
} }
isLoggedIn.value = true isLoggedIn.value = true
@ -50,9 +49,18 @@ const login = handleSubmit(async (form) => {
</script> </script>
<template> <template>
<main class="w-50 m-auto"> <main class="w-50 m-auto max-w-[250px]">
<CustomLogo class="flex-none mx-auto w-1/2 mb-10" /> <CustomLogo class="flex-none mx-auto w-1/2 mb-10" />
<BaseAlert
v-if="redirectUrl"
variant="warning"
icon="alert-outline"
:message="t('ssowat.protected')"
class="mb-4"
assertive
/>
<form novalidate @submit="login"> <form novalidate @submit="login">
<FormField <FormField
name="username" name="username"