-
Notifications
You must be signed in to change notification settings - Fork 0
/
+layout.svelte
63 lines (56 loc) · 1.25 KB
/
+layout.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts">
import './styles.css';
import { onAuthStateChanged } from 'firebase/auth';
import { goto } from '$app/navigation';
import { Modals, closeModal } from 'svelte-modals';
import { browser } from '$app/environment';
import { auth } from '$lib/firebase';
import type { User } from '$lib/types';
import { isLoggedIn, user } from '$stores/auth';
import Profile from './Profile.svelte';
onAuthStateChanged(auth, (authUser) => {
if (!!authUser) {
user.set({ ...authUser } as User);
browser && goto('/');
} else {
browser && goto('/signin');
}
isLoggedIn.set(!!authUser);
});
</script>
{#if $isLoggedIn}
<nav>
<a href="/"> Note-ie </a>
<Profile />
</nav>
{/if}
<slot />
<Modals>
<div class="backdrop" slot="backdrop" on:click={closeModal} />
</Modals>
<style>
nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: var(--color-on-bg);
padding: 0 var(--padding);
border-radius: var(--border-radius);
position: sticky;
top: 1rem;
margin: var(--padding);
height: 4rem;
}
a {
text-decoration: none;
color: var(--color-fg);
}
.backdrop {
position: fixed;
top: 0;
left: 0;
background-color: var(--color-shadow);
width: 100vw;
height: 100vh;
}
</style>