Availability based on permissions

This commit is contained in:
cdricms
2025-02-19 16:16:47 +01:00
parent 446813315d
commit 2011ae93b6
26 changed files with 1071 additions and 794 deletions

22
frontend/lib/getMe.ts Normal file
View File

@@ -0,0 +1,22 @@
import { cache } from "react";
import { API_URL } from "./constants";
import { ApiResponse } from "@/types/types";
import IUser from "@/interfaces/IUser";
import { cookies } from "next/headers";
const getMe = cache(
async (sessionCookie?: string): Promise<ApiResponse<IUser> | null> => {
if (!sessionCookie) {
const store = await cookies();
const token = store.get("auth_token")?.value;
if (!token) return null;
sessionCookie = token;
}
const res = await fetch(`${API_URL}/users/me`, {
headers: { Authorization: `Bearer ${sessionCookie}` },
});
return await res.json();
},
);
export default getMe;