Compare commits
5 Commits
a581480ae1
...
46eb892f51
Author | SHA1 | Date | |
---|---|---|---|
46eb892f51 | |||
92d3a15420 | |||
aa5a173e83 | |||
9dbce2b331 | |||
60c22c5350 |
16
src/routes/+layout.server.ts
Normal file
16
src/routes/+layout.server.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
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");
|
||||
}
|
||||
}
|
|
@ -1,6 +1 @@
|
|||
<p>
|
||||
<a href="/ping">ping</a>
|
||||
<a href="/test">test</a>
|
||||
<a href="/test2">test2</a>
|
||||
<a href="/login">login</a>
|
||||
</p>
|
||||
<p>Hello, World!</p>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// src/routes/api/auth/login/+server.ts
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { login } from '$lib/api';
|
||||
import type { PageServerLoad } from '../../../test2/$types';
|
||||
|
||||
export async function POST({ request, cookies }) {
|
||||
export const POST: PageServerLoad = async ({ request, cookies }) => {
|
||||
console.log("in POST1")
|
||||
const authToken = request.headers.get('App-Token');
|
||||
console.log("authToken = ", authToken)
|
||||
|
@ -22,7 +23,7 @@ export async function POST({ request, cookies }) {
|
|||
console.log("in POST5")
|
||||
return json({ id: loginResponse.id, name: loginResponse.name });
|
||||
} catch (error) {
|
||||
return json({ error: error.message }, { status: 401 });
|
||||
return json({ error: error }, { status: 401 });
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<script>
|
||||
import { goto } from "$app/navigation";
|
||||
import { addSuccessToast } from "$lib/components/store";
|
||||
import Toasts from "$lib/components/Toasts.svelte";
|
||||
let username = $state("");
|
||||
|
@ -23,8 +24,7 @@
|
|||
credentials: "include", // Important to send cookies with requests
|
||||
});
|
||||
addSuccessToast("Login successful!");
|
||||
// setToken(resp.token);
|
||||
// goto("/test");
|
||||
goto("/");
|
||||
console.log(resp);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
export async function load({ fetch }) {
|
||||
const response = await fetch("https://api.fin.qowevisa.click/api/authping", {
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
return {
|
||||
message: await response.json()
|
||||
};
|
||||
}
|
9
src/routes/test2/+page.server.ts
Normal file
9
src/routes/test2/+page.server.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
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()
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user