27 lines
919 B
TypeScript
27 lines
919 B
TypeScript
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
|
import { checkAuthorizationHeader, checkAuthorizationHeaderNoThrow } from "#lib/middleware/authorization.js";
|
|
import { AstroGlobal } from "astro";
|
|
import { Enums } from "#lib/client/prisma.js";
|
|
import { prisma } from "#lib/server/prisma.js";
|
|
|
|
export function getCurrentUser(Astro: AstroGlobal) {
|
|
const accessToken = Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
|
|
|
|
return checkAuthorizationHeaderNoThrow(`Bearer ${accessToken}`)
|
|
}
|
|
|
|
export async function getOtherUser(Astro: AstroGlobal, userId : string) {
|
|
const accessToken = Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
|
|
|
|
let currentUser = await checkAuthorizationHeaderNoThrow(`Bearer ${accessToken}`)
|
|
|
|
if (currentUser?.rolle == Enums.BenutzerRolle.ADMIN) {
|
|
const user = await prisma.benutzer.findUnique({
|
|
where: {
|
|
id: userId
|
|
}
|
|
})
|
|
return user;
|
|
}
|
|
return null;
|
|
} |