maiboyer have finished
Verification of the maiboyer's modules
This commit is contained in:
commit
64a820c0f0
6 changed files with 49 additions and 17 deletions
|
|
@ -17,8 +17,8 @@
|
||||||
<span class="arrow back"><</span>
|
<span class="arrow back"><</span>
|
||||||
</button>
|
</button>
|
||||||
<div id="header-title" class="text-white text-lf text-semibold ps-4 shadow-md font-mono"></div>
|
<div id="header-title" class="text-white text-lf text-semibold ps-4 shadow-md font-mono"></div>
|
||||||
<div class="text-white text-lf ps-4 font-mono"> </div>
|
<div class="text-white text-lf ps-4 font-mono"> </div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- Sidebar -->
|
<!-- Sidebar -->
|
||||||
<aside id="sidebar"
|
<aside id="sidebar"
|
||||||
|
|
@ -34,9 +34,11 @@
|
||||||
</nav>
|
</nav>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
<div class="fixed top-0 left-0 opacity-40" hidden> <!-- >this is used so tailwind create the class styles... -->
|
||||||
|
</div>
|
||||||
<!-- Overlay -->
|
<!-- Overlay -->
|
||||||
<div id="overlay"
|
<div id="overlay"
|
||||||
class="fixed top-14 left-0 right-0 bottom-0 bg-black bg-opacity-40 opacity-0 pointer-events-none transition-opacity duration-300 z-30">
|
class="fixed top-14 left-0 right-0 bottom-0 bg-black opacity-0 pointer-events-none transition-opacity duration-300 z-30">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Main content -->
|
<!-- Main content -->
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
import { showError } from "@app/toast";
|
import { showError } from "@app/toast";
|
||||||
import client from '@app/api';
|
import client from '@app/api';
|
||||||
|
import cookie from 'js-cookie';
|
||||||
|
|
||||||
|
cookie.remove('pkce');
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const overlay = document.querySelector('#overlay')!;
|
||||||
menuBtn.addEventListener('click', () => {
|
menuBtn.addEventListener('click', () => {
|
||||||
sidebar.classList.toggle('-translate-x-full')
|
sidebar.classList.toggle('-translate-x-full')
|
||||||
overlay.classList.toggle('opacity-0');
|
overlay.classList.toggle('opacity-0');
|
||||||
|
overlay.classList.toggle('opacity-40');
|
||||||
overlay.classList.toggle('pointer-events-none');
|
overlay.classList.toggle('pointer-events-none');
|
||||||
menuBtn.classList.toggle('flipped');
|
menuBtn.classList.toggle('flipped');
|
||||||
});
|
});
|
||||||
|
|
@ -14,4 +15,5 @@ menuBtn.addEventListener('click', () => {
|
||||||
overlay.addEventListener('click', () => {
|
overlay.addEventListener('click', () => {
|
||||||
sidebar.classList.add('-translate-x-full');
|
sidebar.classList.add('-translate-x-full');
|
||||||
overlay.classList.add('opacity-0', 'pointer-events-none');
|
overlay.classList.add('opacity-0', 'pointer-events-none');
|
||||||
|
overlay.classList.remove('opacity-40');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import './login/login.ts'
|
||||||
import './signin/signin.ts'
|
import './signin/signin.ts'
|
||||||
import './ttt/ttt.ts'
|
import './ttt/ttt.ts'
|
||||||
import './profile/profile.ts'
|
import './profile/profile.ts'
|
||||||
|
import './logout/logout.ts'
|
||||||
|
|
||||||
// ---- Initial load ----
|
// ---- Initial load ----
|
||||||
setTitle("");
|
setTitle("");
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,11 @@ import { updateUser } from "@app/auth";
|
||||||
|
|
||||||
const TOTP_LENGTH = 6;
|
const TOTP_LENGTH = 6;
|
||||||
|
|
||||||
async function handleOtp(app: HTMLElement, token: string, returnTo: string | null) {
|
async function handleOtp(
|
||||||
|
app: HTMLElement,
|
||||||
|
token: string,
|
||||||
|
returnTo: string | null,
|
||||||
|
) {
|
||||||
app.innerHTML = totpHtml;
|
app.innerHTML = totpHtml;
|
||||||
|
|
||||||
const container = app.querySelector("#totp-container")!;
|
const container = app.querySelector("#totp-container")!;
|
||||||
|
|
@ -76,19 +80,18 @@ async function handleOtp(app: HTMLElement, token: string, returnTo: string | nul
|
||||||
if (code.length === TOTP_LENGTH && /^[0-9]+$/.test(code)) {
|
if (code.length === TOTP_LENGTH && /^[0-9]+$/.test(code)) {
|
||||||
let res = await client.loginOtp({
|
let res = await client.loginOtp({
|
||||||
loginOtpRequest: {
|
loginOtpRequest: {
|
||||||
code, token,
|
code,
|
||||||
}
|
token,
|
||||||
})
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (res.kind === "success") {
|
if (res.kind === "success") {
|
||||||
Cookie.set("token", res.payload.token, {
|
Cookie.set("token", res.payload.token, {
|
||||||
path: "/",
|
path: "/",
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
});
|
});
|
||||||
if (returnTo !== null) navigateTo(returnTo);
|
navigateTo(returnTo ?? "/");
|
||||||
else navigateTo("/");
|
} else if (res.kind === "failed") {
|
||||||
}
|
|
||||||
else if (res.kind === "failed") {
|
|
||||||
showError(`Failed to authenticate: ${res.msg}`);
|
showError(`Failed to authenticate: ${res.msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +100,6 @@ async function handleOtp(app: HTMLElement, token: string, returnTo: string | nul
|
||||||
inputs[0].focus();
|
inputs[0].focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleLogin(
|
async function handleLogin(
|
||||||
_url: string,
|
_url: string,
|
||||||
_args: RouteHandlerParams,
|
_args: RouteHandlerParams,
|
||||||
|
|
@ -131,7 +133,7 @@ async function handleLogin(
|
||||||
if (returnTo !== null) {
|
if (returnTo !== null) {
|
||||||
bReturnTo.parentElement!.hidden = false;
|
bReturnTo.parentElement!.hidden = false;
|
||||||
bReturnTo.addEventListener("click", async () => {
|
bReturnTo.addEventListener("click", async () => {
|
||||||
if (returnTo !== null) navigateTo(returnTo);
|
navigateTo(returnTo ?? "/");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -189,11 +191,15 @@ async function handleLogin(
|
||||||
setTitle(
|
setTitle(
|
||||||
`Welcome ${user.guest ? "[GUEST] " : ""}${user.name}`,
|
`Welcome ${user.guest ? "[GUEST] " : ""}${user.name}`,
|
||||||
);
|
);
|
||||||
if (returnTo !== null) navigateTo(returnTo);
|
navigateTo(returnTo ?? "/");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "otpRequired": {
|
case "otpRequired": {
|
||||||
return await handleOtp(app!, res.payload.token, returnTo);
|
return await handleOtp(
|
||||||
|
app!,
|
||||||
|
res.payload.token,
|
||||||
|
returnTo,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
case "failed": {
|
case "failed": {
|
||||||
showError(`Failed to login: ${res.msg}`);
|
showError(`Failed to login: ${res.msg}`);
|
||||||
|
|
@ -209,7 +215,9 @@ async function handleLogin(
|
||||||
document.querySelector<HTMLButtonElement>("#bGuestLogin");
|
document.querySelector<HTMLButtonElement>("#bGuestLogin");
|
||||||
bLoginAsGuest?.addEventListener("click", async () => {
|
bLoginAsGuest?.addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
const res = await client.guestLogin({ guestLoginRequest: { name: undefined } });
|
const res = await client.guestLogin({
|
||||||
|
guestLoginRequest: { name: undefined },
|
||||||
|
});
|
||||||
switch (res.kind) {
|
switch (res.kind) {
|
||||||
case "success": {
|
case "success": {
|
||||||
Cookie.set("token", res.payload.token, {
|
Cookie.set("token", res.payload.token, {
|
||||||
|
|
@ -224,7 +232,7 @@ async function handleLogin(
|
||||||
setTitle(
|
setTitle(
|
||||||
`Welcome ${user.guest ? "[GUEST] " : ""}${user.name}`,
|
`Welcome ${user.guest ? "[GUEST] " : ""}${user.name}`,
|
||||||
);
|
);
|
||||||
if (returnTo !== null) navigateTo(returnTo);
|
navigateTo(returnTo ?? "/");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "failed": {
|
case "failed": {
|
||||||
|
|
|
||||||
16
frontend/src/pages/logout/logout.ts
Normal file
16
frontend/src/pages/logout/logout.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { addRoute, navigateTo, setTitle, type RouteHandlerReturn } from "@app/routing";
|
||||||
|
import cookie from "js-cookie";
|
||||||
|
|
||||||
|
async function route(_url: string, _args: { [k: string]: string }): Promise<RouteHandlerReturn> {
|
||||||
|
setTitle('Logout')
|
||||||
|
return {
|
||||||
|
html: "you should have been logged out", postInsert: async (app) => {
|
||||||
|
cookie.remove("token");
|
||||||
|
navigateTo("/");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
addRoute('/logout', route, { bypass_auth: true })
|
||||||
Loading…
Add table
Add a link
Reference in a new issue