|
|
@@ -7,16 +7,24 @@
|
|
|
let username = null;
|
|
|
let profileTitle = null;
|
|
|
|
|
|
- $: auth.subscribe(value => {
|
|
|
+ const unsubscribe = auth.subscribe(value => {
|
|
|
username = value ? value.username : "";
|
|
|
- profileTitle = value ? "You are logged in as " + value.username : "login";
|
|
|
+ profileTitle = value ? `You are logged in as ${value.username}` : "Login";
|
|
|
});
|
|
|
|
|
|
onMount(() => {
|
|
|
const storedAuth = localStorage.getItem('auth');
|
|
|
if (storedAuth) {
|
|
|
- auth.set(JSON.parse(storedAuth));
|
|
|
+ try {
|
|
|
+ auth.set(JSON.parse(storedAuth));
|
|
|
+ } catch (e) {
|
|
|
+ console.error("Failed to parse auth from localStorage", e);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ unsubscribe();
|
|
|
+ };
|
|
|
});
|
|
|
|
|
|
</script>
|