3Dbelte in gitea
This commit is contained in:
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