Frontend working. Added form vendor profilke

This commit is contained in:
2025-06-10 16:57:52 -04:00
parent a4188c623d
commit 06a5ff98d7
8 changed files with 183 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { user } from '$lib/states';
import type { LoginRequest } from '$lib/types/types';
let username = '';
@@ -17,7 +18,7 @@
errorMessage = '';
try {
const response = await fetch('/login', {
const response = await fetch('http://localhost:9552/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@@ -31,8 +32,18 @@
} else {
const data = await response.json();
// Assuming the backend returns a token or some success indicator
// Redirect to home page or dashboard after successful login
goto('/');
// Store the token in localStorage for authentication checks
if (data.token) {
localStorage.setItem('auth_token', data.token);
}
// Store the user object in localStorage
localStorage.setItem('user', JSON.stringify(data.user));
// Update the user store
user.set(data.user);
// Redirect to vendor page after successful login
goto('/vendor');
}
} catch (err) {
errorMessage = 'An error occurred. Please try again.';
@@ -107,5 +118,10 @@
</button>
</div>
</form>
<div class="mt-4 text-center">
<p class="text-sm text-gray-600">
Not registered yet? <a href="/register" class="font-medium text-indigo-600 hover:text-indigo-500">Register here</a>
</p>
</div>
</div>
</div>