Benutzerdaten beim Speichern/Bestellen als Admin in Tabelle Benutzer speichern
This commit is contained in:
@@ -1,9 +1,27 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user