init commit
This commit is contained in:
commit
dfe324cf8f
43 changed files with 4237 additions and 0 deletions
87
src/lib/MainNavbar.svelte
Normal file
87
src/lib/MainNavbar.svelte
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { PUBLIC_BACKEND_API_HOST } from "$env/static/public";
|
||||
import { auth, setUserLoggedOut } from "./auth.svelte";
|
||||
|
||||
async function toggleMfa() {
|
||||
try {
|
||||
const res = await fetch(`${PUBLIC_BACKEND_API_HOST}/api/v1/user/update-mfa`, {
|
||||
credentials: "include",
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ enable_mfa: auth.isMfaEnabled }),
|
||||
});
|
||||
|
||||
if (res.status === 401 || res.status === 500) {
|
||||
setUserLoggedOut();
|
||||
goto('/login');
|
||||
throw new Error('Unauthorized');
|
||||
} else if (res.status !== 204) {
|
||||
let msg = await res.text();
|
||||
throw new Error(`Failed updating MFA: ${msg}`);
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: show error to user
|
||||
console.error(err);
|
||||
auth.isMfaEnabled = !auth.isMfaEnabled;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="navbar bg-base-100 shadow-sm top-0 z-10 py-0">
|
||||
<div class="navbar-start">
|
||||
<div class="dropdown">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16" /> </svg>
|
||||
</div>
|
||||
<ul
|
||||
tabindex="-1"
|
||||
class="menu menu-sm dropdown-content bg-base-100 rounded-box z-1 mt-3 w-52 p-2 shadow">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/about">About us</a></li>
|
||||
<li><a href="/faq">FAQ</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="btn btn-ghost text-xl" href="/">HexName</a>
|
||||
</div>
|
||||
<div class="navbar-center hidden lg:flex">
|
||||
<ul class="menu menu-horizontal px-1">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/about">About us</a></li>
|
||||
<li><a href="/faq">FAQ</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
{#if auth.isAuthenticated}
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="0" role="button" class="btn btn-ghost btn-circle avatar">
|
||||
<svg class="size-9" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="#dfe5ed"><path stroke-linecap="round" stroke-linejoin="round" d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.963 0a9 9 0 1 0-11.963 0m11.963 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /></svg>
|
||||
</div>
|
||||
<ul
|
||||
tabindex="-1"
|
||||
class="menu menu-sm dropdown-content bg-base-200 rounded-box z-10 mt-3 w-52 p-2 shadow">
|
||||
<li><text class="font-bold">{auth.userEmail}</text></li>
|
||||
<li>
|
||||
<div class="justify-between">
|
||||
2-factor via email
|
||||
<label class="toggle text-base-content outline-transparent">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={auth.isMfaEnabled}
|
||||
on:change={toggleMfa}
|
||||
/>
|
||||
<svg class="outline-transparent" aria-label="disabled" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18" /><path d="m6 6 12 12"/></svg>
|
||||
<svg class="outline-transparent" aria-label="enabled" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g stroke-linejoin="round" stroke-linecap="round" stroke-width="4" fill="none" stroke="currentColor"><path d="M20 6 9 17l-5-5"></path></g></svg>
|
||||
</label>
|
||||
</div>
|
||||
</li>
|
||||
<li><a href="/delete-account">Delete account</a></li>
|
||||
<li><a href="/logout">Log out</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{:else}
|
||||
<a href="/register"><button class="btn btn-sm btn-primary rounded-lg mr-2">Create an account</button></a>
|
||||
<a href="/login"><button class="btn btn-sm btn-secondary rounded-lg mr-2">Log in</button></a>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue