front > login : fix redirection when user is already logged in
This commit is contained in:
parent
e30a80c4ff
commit
619e124fc4
3 changed files with 25 additions and 14 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return function ($page, $kirby, $site) {
|
return function ($page, $kirby, $site) {
|
||||||
|
if (!$kirby->user() && $page->uri() !== 'login') {
|
||||||
|
go('/login');
|
||||||
|
}
|
||||||
|
|
||||||
$data = $page->toArray();
|
$data = $page->toArray();
|
||||||
$data['template'] = (string) $page->template();
|
$data['template'] = (string) $page->template();
|
||||||
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
|
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,13 @@ router.beforeEach(async (to, from, next) => {
|
||||||
try {
|
try {
|
||||||
const res = await api.fetchData(to.path);
|
const res = await api.fetchData(to.path);
|
||||||
|
|
||||||
if (!res.user && to.path === '/login' && from.path === '/login') {
|
if (to.path === '/login' && res.user) {
|
||||||
next();
|
location.href = '/';
|
||||||
} else if (res.user && to.path === '/login') {
|
|
||||||
next('/');
|
|
||||||
} else {
|
|
||||||
pageStore.page = res.page;
|
|
||||||
userStore.user = res.user;
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageStore.page = res.page;
|
||||||
|
userStore.user = res.user;
|
||||||
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
next(false);
|
next(false);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
placeholder="mail@exemple.com"
|
placeholder="mail@exemple.com"
|
||||||
autocomplete="username"
|
autocomplete="username"
|
||||||
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
||||||
:class="{ invalid: !isValidEmail }"
|
:class="{ invalid: emailRegex.test(email) }"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<p v-else>Email : {{ user.email }}</p>
|
<p v-else>Email : {{ user.email }}</p>
|
||||||
|
|
@ -23,6 +23,17 @@
|
||||||
modifier
|
modifier
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
<li :class="{ 'is-editing': isEditingEmail }">
|
||||||
|
<input
|
||||||
|
@input="updatePassword"
|
||||||
|
type="password"
|
||||||
|
v-model="password"
|
||||||
|
id="password"
|
||||||
|
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
||||||
|
:class="{ invalid: password.length < 8 }"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>Client : {{ user.client.name }}</p>
|
<p>Client : {{ user.client.name }}</p>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -37,14 +48,12 @@ import { useUserStore } from '../stores/user';
|
||||||
import { ref, watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
|
|
||||||
const { user } = storeToRefs(useUserStore());
|
const { user } = storeToRefs(useUserStore());
|
||||||
|
|
||||||
const email = ref('');
|
const email = ref('');
|
||||||
const isEditingEmail = ref(false);
|
const isEditingEmail = ref(false);
|
||||||
const isValidEmail = ref(false);
|
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||||
|
|
||||||
watch(email, (newEmail) => {
|
const password = ref('');
|
||||||
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
||||||
isValidEmail.value = regex.test(newEmail);
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateEmail(event) {
|
function updateEmail(event) {
|
||||||
email.value = event.target.value;
|
email.value = event.target.value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue