Login update
This commit is contained in:
@@ -26,7 +26,7 @@ builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("SeasonedOriginPolicy", policy =>
|
||||
{
|
||||
policy.WithOrigins("https://https://seasoned.ddns.net")
|
||||
policy.WithOrigins("https://seasoned.ddns.net")
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
/* Enhancing the custom-input for Auth with icons */
|
||||
.auth-input .v-field__prepend-inner {
|
||||
display: flex !important; /* Overriding the 'display: none' from app-theme.css */
|
||||
display: flex !important;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@
|
||||
</div>
|
||||
|
||||
<v-btn
|
||||
to="/gallery"
|
||||
class="gallery-btn w-100 mt-4"
|
||||
size="large"
|
||||
elevation="0"
|
||||
@click="handleViewCollection"
|
||||
>
|
||||
<v-icon icon="mdi-book-open-variant" class="mr-2"></v-icon>
|
||||
View Collection
|
||||
@@ -124,8 +124,10 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import '@/assets/css/app-theme.css'
|
||||
|
||||
const router = useRouter()
|
||||
const config = useRuntimeConfig()
|
||||
const files = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -134,6 +136,21 @@ const isDragging = ref(false)
|
||||
const saving = 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) => {
|
||||
isDragging.value = false
|
||||
const droppedFiles = e.dataTransfer.files
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
></v-text-field>
|
||||
|
||||
<v-text-field
|
||||
v-model="email"
|
||||
label="Email"
|
||||
placeholder="email@example.com"
|
||||
class="custom-input auth-input mb-4"
|
||||
@@ -28,6 +29,7 @@
|
||||
></v-text-field>
|
||||
|
||||
<v-text-field
|
||||
v-model="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
placeholder="••••••••"
|
||||
@@ -69,36 +71,28 @@
|
||||
const isLogin = ref(true)
|
||||
const email = ref('')
|
||||
const password = ref('')
|
||||
|
||||
const authUrl = '/api/auth/login?useCookies=false'
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const handleAuth = async () => {
|
||||
const endpoint = isLogin.value ? 'api/auth/login' : 'api/auth/register'
|
||||
|
||||
const url = `${config.public.apiBase}${endpoint}?useCookies=false`
|
||||
|
||||
try {
|
||||
const response = await $fetch(isLogin.value ? authUrl : '/api/auth/register', {
|
||||
const response = await $fetch(url, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
email: email.value,
|
||||
userName: email.value,
|
||||
password: password.value
|
||||
}
|
||||
})
|
||||
|
||||
if (isLogin.value && response.accessToken) {
|
||||
const token = useCookie('seasoned_token', {
|
||||
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.")
|
||||
navigateTo('/gallery')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Authentication failed:", err.data?.errors || err)
|
||||
alert("Authentication failed. Check your credentials.")
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -14,7 +14,7 @@ export default defineNuxtConfig({
|
||||
'@mdi/font/css/materialdesignicons.min.css',
|
||||
'~/assets/css/app-theme.css',
|
||||
'~/assets/css/gallery.css',
|
||||
'~/assets/css/auth.css'
|
||||
'~/assets/css/login.css'
|
||||
],
|
||||
|
||||
build: {
|
||||
|
||||
Reference in New Issue
Block a user