Update middleware and deps

This commit is contained in:
Darren Clarke 2023-09-06 16:42:52 +02:00
parent 0b5e242ed0
commit a3d6b786e1
28 changed files with 2246 additions and 2272 deletions

View file

@ -18,6 +18,7 @@ const fetchRoles = async () => {
const fetchUser = async (email: string) => {
const url = `${process.env.ZAMMAD_URL}/api/v1/users/search?query=email:${email}&limit=1`;
console.log({ url });
const res = await fetch(url, { headers });
const users = await res.json();
const user = users?.[0];
@ -40,8 +41,8 @@ const getUserRoles = async (email: string) => {
};
const login = async (email: string, password: string) => {
console.log({ email, password });
const url = `${process.env.ZAMMAD_URL}/api/v1/users/me`;
console.log({ url });
const authorization = 'Basic ' + Buffer.from(email + ":" + password).toString('base64');
const res = await fetch(url, {
headers: {
@ -93,6 +94,7 @@ const handler = NextAuth({
callbacks: {
signIn: async ({ user, account, profile }) => {
console.log("SIGN IN");
const roles = await getUserRoles(user.email) ?? [];
return roles.includes("admin") || roles.includes("agent") || process.env.SETUP_MODE === "true";
},