Răsfoiți Sursa

Upgrade storage

Daniel Bohry 1 an în urmă
părinte
comite
18912ff2b3

+ 4 - 4
src/routes/Header.svelte

@@ -1,22 +1,22 @@
 <script>
     import {page} from '$app/stores';
     import profile from '$lib/images/profile.png';
-    import {auth} from "./store.js";
+    import {authentication} from "./store.js";
     import {onMount} from "svelte";
 
     let username = null;
     let profileTitle = null;
 
-    const unsubscribe = auth.subscribe(value => {
+    const unsubscribe = authentication.subscribe(value => {
         username = value ? value.username : "";
         profileTitle = value ? `You are logged in as ${value.username}` : "Login";
     });
 
     onMount(() => {
-        const storedAuth = localStorage.getItem('auth');
+        const storedAuth = localStorage.getItem('authentication');
         if (storedAuth) {
             try {
-                auth.set(JSON.parse(storedAuth));
+                authentication.set(JSON.parse(storedAuth));
             } catch (e) {
                 console.error("Failed to parse auth from localStorage", e);
             }

+ 6 - 6
src/routes/login/+page.svelte

@@ -1,12 +1,12 @@
 <script>
     import {onMount} from 'svelte';
-    import {auth} from '../store.js';
+    import {authentication} from '../store.js';
 
     let isAuthenticated = false;
     let isLoading = true;
     let user = null;
 
-    $: auth.subscribe(value => {
+    $: authentication.subscribe(value => {
         isAuthenticated = !!value;
         if (value) {
             user = value;
@@ -15,9 +15,9 @@
 
     onMount(() => {
         try {
-            const storedAuth = localStorage.getItem('auth');
+            const storedAuth = localStorage.getItem('authentication');
             if (storedAuth) {
-                auth.set(JSON.parse(storedAuth));
+                authentication.set(JSON.parse(storedAuth));
             }
         } catch (error) {
             console.error('Error parsing stored auth:', error);
@@ -54,8 +54,8 @@
 
             if (response.ok) {
                 const result = await response.json();
-                auth.set(result);
-                localStorage.setItem('auth', JSON.stringify(result));
+                authentication.set(result);
+                localStorage.setItem('authentication', JSON.stringify(result));
             } else {
                 const error = await response.json();
                 console.error('Login failed:', error);

+ 3 - 3
src/routes/logout/+page.svelte

@@ -1,10 +1,10 @@
 <script>
     import {onMount} from "svelte";
-    import {auth} from '../store.js';
+    import {authentication} from '../store.js';
 
     function logout() {
-        auth.set(null);
-        localStorage.removeItem('auth');
+        authentication.set(null);
+        localStorage.removeItem('authentication');
         window.location.href = "/login";
     }
 

+ 2 - 2
src/routes/register/+page.svelte

@@ -1,5 +1,5 @@
 <script>
-    import {auth} from "../store.js";
+    import {authentication} from "../store.js";
 
     async function submit(event) {
         event.preventDefault();
@@ -35,7 +35,7 @@
 
             if (response.ok) {
                 const result = await response.json();
-                auth.set(result);
+                authentication.set(result);
                 localStorage.setItem('auth', JSON.stringify(result));
                 window.location.href = "/login";
             } else {

+ 1 - 1
src/routes/store.js

@@ -1,3 +1,3 @@
 import { writable } from 'svelte/store';
 
-export const auth = writable(null);
+export const authentication = writable(null);