logout functionality hopefully
Some checks failed
Code quality checks / build (23) (push) Successful in 35s
Push code / build (push) Has been cancelled

This commit is contained in:
Lara 2024-11-03 13:23:33 +02:00
parent 16651fce27
commit a967a298cb
Signed by: laratheprotogen
GPG key ID: 5C0296EB3165F98B
7 changed files with 62 additions and 14 deletions

View file

@ -22,6 +22,7 @@
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/eslint": "^9.6.0",
"autoprefixer": "^10.4.20",
"axios": "^1.7.7",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",

View file

@ -1,13 +1,18 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
import type { AxiosInstance } from 'axios';
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
interface Locals {
comm: AxiosInstance;
}
}
}
export {};

View file

@ -0,0 +1,16 @@
import type { Handle } from '@sveltejs/kit';
import axios from 'axios';
export const handle: Handle = async ({ event, resolve }) => {
const apiKey = event.cookies.get('apiKey') ?? '';
event.locals.comm = axios.create({
baseURL: process.env.API_URL,
timeout: 10000,
headers: {
'X-Api-Key': apiKey
}
});
return resolve(event);
};

View file

@ -0,0 +1,13 @@
import { redirect } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
try {
await locals.comm.get('/auth/logout');
} catch (error) {
console.log(error);
return redirect(307, `${process.env.DASHBOARD_URL}/new`);
}
return redirect(307, `${process.env.DASHBOARD_URL}/new`);
};

View file

@ -1,16 +1,11 @@
<script lang="ts">
import logo from '$lib/img/logo.png';
import { page } from '$app/stores';
import { onMount } from 'svelte';
let { children } = $props();
let guildsAnchor: string = $state("/new/dashboard");
onMount(() => {
console.log($page.url.pathname);
})
async function logout() {
}