Login update

This commit is contained in:
2026-03-06 17:04:51 +00:00
parent e20ce70658
commit 3501f36f5f
5 changed files with 32 additions and 21 deletions

View File

@@ -26,7 +26,7 @@ builder.Services.AddCors(options =>
{ {
options.AddPolicy("SeasonedOriginPolicy", policy => options.AddPolicy("SeasonedOriginPolicy", policy =>
{ {
policy.WithOrigins("https://https://seasoned.ddns.net") policy.WithOrigins("https://seasoned.ddns.net")
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.AllowCredentials(); .AllowCredentials();

View File

@@ -16,7 +16,7 @@
/* Enhancing the custom-input for Auth with icons */ /* Enhancing the custom-input for Auth with icons */
.auth-input .v-field__prepend-inner { .auth-input .v-field__prepend-inner {
display: flex !important; /* Overriding the 'display: none' from app-theme.css */ display: flex !important;
padding-right: 12px; padding-right: 12px;
} }

View File

@@ -61,10 +61,10 @@
</div> </div>
<v-btn <v-btn
to="/gallery"
class="gallery-btn w-100 mt-4" class="gallery-btn w-100 mt-4"
size="large" size="large"
elevation="0" elevation="0"
@click="handleViewCollection"
> >
<v-icon icon="mdi-book-open-variant" class="mr-2"></v-icon> <v-icon icon="mdi-book-open-variant" class="mr-2"></v-icon>
View Collection View Collection
@@ -124,8 +124,10 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { useRouter } from 'vue-router'
import '@/assets/css/app-theme.css' import '@/assets/css/app-theme.css'
const router = useRouter()
const config = useRuntimeConfig() const config = useRuntimeConfig()
const files = ref([]) const files = ref([])
const loading = ref(false) const loading = ref(false)
@@ -134,6 +136,21 @@ const isDragging = ref(false)
const saving = ref(false) const saving = ref(false)
const hasSaved = ref(false) const hasSaved = ref(false)
const isAuthenticated = () => {
if (import.meta.client) {
return !!localStorage.getItem('token');
}
return false;
}
const handleViewCollection = () => {
if (isAuthenticated()) {
router.push('/gallery')
} else {
router.push('/login')
}
}
const handleDrop = (e) => { const handleDrop = (e) => {
isDragging.value = false isDragging.value = false
const droppedFiles = e.dataTransfer.files const droppedFiles = e.dataTransfer.files

View File

@@ -20,6 +20,7 @@
></v-text-field> ></v-text-field>
<v-text-field <v-text-field
v-model="email"
label="Email" label="Email"
placeholder="email@example.com" placeholder="email@example.com"
class="custom-input auth-input mb-4" class="custom-input auth-input mb-4"
@@ -28,6 +29,7 @@
></v-text-field> ></v-text-field>
<v-text-field <v-text-field
v-model="password"
label="Password" label="Password"
type="password" type="password"
placeholder="••••••••" placeholder="••••••••"
@@ -69,36 +71,28 @@
const isLogin = ref(true) const isLogin = ref(true)
const email = ref('') const email = ref('')
const password = ref('') const password = ref('')
const config = useRuntimeConfig()
const authUrl = '/api/auth/login?useCookies=false'
const handleAuth = async () => { const handleAuth = async () => {
const endpoint = isLogin.value ? 'api/auth/login' : 'api/auth/register'
const url = `${config.public.apiBase}${endpoint}?useCookies=false`
try { try {
const response = await $fetch(isLogin.value ? authUrl : '/api/auth/register', { const response = await $fetch(url, {
method: 'POST', method: 'POST',
body: { body: {
email: email.value, email: email.value,
userName: email.value,
password: password.value password: password.value
} }
}) })
if (isLogin.value && response.accessToken) { if (isLogin.value && response.accessToken) {
const token = useCookie('seasoned_token', { navigateTo('/gallery')
maxAge: response.expiresIn,
sameSite: 'lax',
secure: true,
path: '/'
})
token.value = response.accessToken
navigateTo('/gallery')
} else if (!isLogin.value) {
isLogin.value = true
alert("Account created. Please sign in to open your ledger.")
} }
} catch (err) { } catch (err) {
console.error("Authentication failed:", err.data?.errors || err) alert("Authentication failed. Check your credentials.")
} }
} }
</script> </script>

View File

@@ -14,7 +14,7 @@ export default defineNuxtConfig({
'@mdi/font/css/materialdesignicons.min.css', '@mdi/font/css/materialdesignicons.min.css',
'~/assets/css/app-theme.css', '~/assets/css/app-theme.css',
'~/assets/css/gallery.css', '~/assets/css/gallery.css',
'~/assets/css/auth.css' '~/assets/css/login.css'
], ],
build: { build: {