3Dbelte in gitea
This commit is contained in:
12
3Dbelte/src/app.d.ts
vendored
Normal file
12
3Dbelte/src/app.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
12
3Dbelte/src/app.html
Normal file
12
3Dbelte/src/app.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
7
3Dbelte/src/index.test.js
Normal file
7
3Dbelte/src/index.test.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('sum test', () => {
|
||||
it('adds 1 + 2 to equal 3', () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
});
|
||||
50
3Dbelte/src/routes/+page.svelte
Normal file
50
3Dbelte/src/routes/+page.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script>
|
||||
import { writable } from 'svelte/store';
|
||||
const token = writable('');
|
||||
const payload = writable();
|
||||
const onSendClick = async () => {
|
||||
const response = await fetch('/api/login', { method: 'POST' });
|
||||
const data = await response.json();
|
||||
$token = data?.token;
|
||||
};
|
||||
const onReadClick = async () => {
|
||||
const response = await fetch('/api/me', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${$token}`
|
||||
}
|
||||
});
|
||||
$payload = await response.json();
|
||||
};
|
||||
</script>
|
||||
<h1>Welcome to 3D-Belte</h1>
|
||||
<p>Visit <a href="/about">about page</a> to read the documentation. First press send, than read.</p>
|
||||
<div class="body">
|
||||
<div class="form">
|
||||
<span>JWT Token</span>
|
||||
<textarea>{$token}</textarea>
|
||||
<span>Payload</span>
|
||||
<textarea>{JSON.stringify($payload)}</textarea>
|
||||
<button on:click={onSendClick}>send</button>
|
||||
<button on:click={onReadClick}>read</button>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
.body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
align-content: center;
|
||||
}
|
||||
.form {
|
||||
width: 500px;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
</style>
|
||||
|
||||
1
3Dbelte/src/routes/about/+page.svelte
Normal file
1
3Dbelte/src/routes/about/+page.svelte
Normal file
@@ -0,0 +1 @@
|
||||
<p> Dies ist eine Dokumentation </p>
|
||||
10
3Dbelte/src/routes/api/login/+server.js
Normal file
10
3Dbelte/src/routes/api/login/+server.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export async function POST() {
|
||||
const token = await jwt.sign({
|
||||
id: 'sample-id',
|
||||
secret: 'secret'
|
||||
},"shhhhh");
|
||||
return json({ token });
|
||||
}
|
||||
14
3Dbelte/src/routes/api/me/+server.js
Normal file
14
3Dbelte/src/routes/api/me/+server.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { verify } from 'jsonwebtoken';
|
||||
|
||||
export function GET({ request }) {
|
||||
const authorization = request.headers.get('authorization');
|
||||
try {
|
||||
const jwt = authorization.slice(7);
|
||||
const decoded = verify(jwt, 'shhhhh');
|
||||
return json(decoded);
|
||||
} catch (err) {
|
||||
throw error(404, { message: err.message });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user