login update
This commit is contained in:
@@ -10,7 +10,14 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
builder.Services.AddScoped<IRecipeService, RecipeService>();
|
builder.Services.AddScoped<IRecipeService, RecipeService>();
|
||||||
|
|
||||||
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
|
builder.Services.AddIdentityApiEndpoints<IdentityUser>( options => {
|
||||||
|
options.Password.RequireDigit = false;
|
||||||
|
options.Password.RequiredLength = 6;
|
||||||
|
options.Password.RequireNonAlphanumeric = false;
|
||||||
|
options.Password.RequireUppercase = false;
|
||||||
|
options.Password.RequireLowercase = false;
|
||||||
|
options.User.RequireUniqueEmail = true;
|
||||||
|
})
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||||
|
|
||||||
builder.Services.AddAuthorization();
|
builder.Services.AddAuthorization();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container class="fill-height">
|
<v-container class="fill-height">
|
||||||
<v-card class="recipe-card auth-card pa-10 mx-auto" elevation="10">
|
<v-card class="recipe-card auth-card pa-10 mx-auto" elevation="10" max-width="500">
|
||||||
|
|
||||||
<v-fade-transition mode="out-in">
|
<v-fade-transition mode="out-in">
|
||||||
<div :key="isLogin">
|
<div :key="isLogin">
|
||||||
@@ -10,15 +10,6 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<v-form @submit.prevent="handleAuth">
|
<v-form @submit.prevent="handleAuth">
|
||||||
<v-text-field
|
|
||||||
v-if="!isLogin"
|
|
||||||
label="Name"
|
|
||||||
placeholder="Your name"
|
|
||||||
class="custom-input auth-input mb-4"
|
|
||||||
variant="flat"
|
|
||||||
prepend-inner-icon="mdi-account-outline"
|
|
||||||
></v-text-field>
|
|
||||||
|
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="email"
|
v-model="email"
|
||||||
label="Email"
|
label="Email"
|
||||||
@@ -49,7 +40,7 @@
|
|||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<span class="auth-toggle-btn" @click="isLogin = !isLogin">
|
<span class="auth-toggle-btn" @click="isLogin = !isLogin" style="cursor: pointer;">
|
||||||
{{ isLogin ? "New here? Register an account" : "Already a member? Sign in" }}
|
{{ isLogin ? "New here? Register an account" : "Already a member? Sign in" }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -76,7 +67,9 @@ const config = useRuntimeConfig()
|
|||||||
const handleAuth = async () => {
|
const handleAuth = async () => {
|
||||||
const endpoint = isLogin.value ? 'api/auth/login' : 'api/auth/register'
|
const endpoint = isLogin.value ? 'api/auth/login' : 'api/auth/register'
|
||||||
|
|
||||||
const url = `${config.public.apiBase}${endpoint}?useCookies=false`
|
const url = isLogin.value
|
||||||
|
? `${config.public.apiBase}${endpoint}?useCookies=false`
|
||||||
|
: `${config.public.apiBase}${endpoint}`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await $fetch(url, {
|
const response = await $fetch(url, {
|
||||||
@@ -88,11 +81,28 @@ const handleAuth = async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isLogin.value && response.accessToken) {
|
if (isLogin.value) {
|
||||||
|
if (response.accessToken) {
|
||||||
|
|
||||||
|
const tokenCookie = useCookie('seasoned_token', { maxAge: response.expiresIn })
|
||||||
|
tokenCookie.value = response.accessToken
|
||||||
|
|
||||||
|
if (import.meta.client) {
|
||||||
|
localStorage.setItem('token', response.accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
navigateTo('/gallery')
|
navigateTo('/gallery')
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
alert("Account created successfully! Please sign in to open your ledger.")
|
||||||
|
isLogin.value = true
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("Authentication failed. Check your credentials.")
|
const errorDetail = err.data?.errors
|
||||||
|
? Object.values(err.data.errors).flat().join('\n')
|
||||||
|
: "Check your credentials and try again."
|
||||||
|
|
||||||
|
alert(`Authentication failed:\n${errorDetail}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user