Compare commits

..

No commits in common. "46eb892f51b212a057386ad99fc4a1e862d0f005" and "a581480ae1cdf1c5019b42c5c8b57af4b226ce72" have entirely different histories.

6 changed files with 19 additions and 31 deletions

View File

@ -1,16 +0,0 @@
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = async ({ url, fetch, cookies }) => {
if (url.pathname == "/login") {
return
}
console.log("what?")
const response = await fetch("https://api.fin.qowevisa.click/api/authping");
if (!response.ok) {
cookies.delete('session', { path: "/" })
throw redirect(302, "/login");
}
}

View File

@ -1 +1,6 @@
<p>Hello, World!</p>
<p>
<a href="/ping">ping</a>
<a href="/test">test</a>
<a href="/test2">test2</a>
<a href="/login">login</a>
</p>

View File

@ -1,9 +1,8 @@
// src/routes/api/auth/login/+server.ts
import { json } from '@sveltejs/kit';
import { login } from '$lib/api';
import type { PageServerLoad } from '../../../test2/$types';
export const POST: PageServerLoad = async ({ request, cookies }) => {
export async function POST({ request, cookies }) {
console.log("in POST1")
const authToken = request.headers.get('App-Token');
console.log("authToken = ", authToken)
@ -23,7 +22,7 @@ export const POST: PageServerLoad = async ({ request, cookies }) => {
console.log("in POST5")
return json({ id: loginResponse.id, name: loginResponse.name });
} catch (error) {
return json({ error: error }, { status: 401 });
return json({ error: error.message }, { status: 401 });
}
}

View File

@ -1,5 +1,4 @@
<script>
import { goto } from "$app/navigation";
import { addSuccessToast } from "$lib/components/store";
import Toasts from "$lib/components/Toasts.svelte";
let username = $state("");
@ -24,7 +23,8 @@
credentials: "include", // Important to send cookies with requests
});
addSuccessToast("Login successful!");
goto("/");
// setToken(resp.token);
// goto("/test");
console.log(resp);
} catch (err) {
if (err instanceof Error) {

View File

@ -0,0 +1,9 @@
export async function load({ fetch }) {
const response = await fetch("https://api.fin.qowevisa.click/api/authping", {
credentials: "include",
});
return {
message: await response.json()
};
}

View File

@ -1,9 +0,0 @@
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ fetch }) => {
const response = await fetch("https://api.fin.qowevisa.click/api/authping");
return {
message: await response.json()
};
}