Update deps

This commit is contained in:
Darren Clarke 2024-03-03 18:13:26 +01:00
parent 6663e8ed1e
commit 486f989494
33 changed files with 776 additions and 695 deletions

View file

@ -9,6 +9,7 @@ const fetchRoles = async () => {
const url = `${process.env.ZAMMAD_URL}/api/v1/roles`;
const res = await fetch(url, { headers });
const roles = await res.json();
console.log({ roles });
const formattedRoles = roles.reduce((acc: any, role: any) => {
acc[role.id] = role.name;
return acc;
@ -17,17 +18,25 @@ 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({ email });
const url = `${process.env.ZAMMAD_URL}/api/v1/users/search?query=login:${email}&limit=1`;
console.log({ url });
const res = await fetch(url, { headers });
console.log({ res });
const users = await res.json();
console.log({ users });
const user = users?.[0];
return user;
// temp
return { role_ids: [1] };
};
const getUserRoles = async (email: string) => {
try {
const user = await fetchUser(email);
console.log({ user });
const allRoles = await fetchRoles();
console.log({ allRoles });
const roles = user.role_ids.map((roleID: number) => {
const role = allRoles[roleID];
return role ? role.toLowerCase().replace(" ", "_") : null;
@ -42,11 +51,12 @@ const getUserRoles = async (email: string) => {
const login = async (email: string, password: string) => {
const url = `${process.env.ZAMMAD_URL}/api/v1/users/me`;
console.log({ url });
const authorization = 'Basic ' + Buffer.from(email + ":" + password).toString('base64');
const authorization =
"Basic " + Buffer.from(email + ":" + password).toString("base64");
const res = await fetch(url, {
headers: {
authorization
}
authorization,
},
});
const user = await res.json();
console.log({ user });
@ -71,13 +81,13 @@ const handler = NextAuth({
}),
Apple({
clientId: process.env.APPLE_CLIENT_ID,
clientSecret: process.env.APPLE_CLIENT_SECRET
clientSecret: process.env.APPLE_CLIENT_SECRET,
}),
Credentials({
name: "Zammad",
credentials: {
email: { label: "Email", type: "text", },
password: { label: "Password", type: "password" }
email: { label: "Email", type: "text" },
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
const user = await login(credentials.email, credentials.password);
@ -86,15 +96,19 @@ const handler = NextAuth({
} else {
return null;
}
}
})
},
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
signIn: async ({ user, account, profile }) => {
const roles = await getUserRoles(user.email) ?? [];
return roles.includes("admin") || roles.includes("agent") || process.env.SETUP_MODE === "true";
const roles = (await getUserRoles(user.email)) ?? [];
return (
roles.includes("admin") ||
roles.includes("agent") ||
process.env.SETUP_MODE === "true"
);
},
session: async ({ session, user, token }) => {
// @ts-ignore
@ -105,13 +119,11 @@ const handler = NextAuth({
},
jwt: async ({ token, user, account, profile, trigger }) => {
if (user) {
token.roles = await getUserRoles(user.email) ?? [];
token.roles = (await getUserRoles(user.email)) ?? [];
}
return token;
}
},
},
});
export { handler as GET, handler as POST };

View file

@ -12,17 +12,17 @@
"@chatscope/chat-ui-kit-react": "^1.10.1",
"@chatscope/chat-ui-kit-styles": "^1.4.0",
"@emotion/cache": "^11.11.0",
"@emotion/react": "^11.11.3",
"@emotion/react": "^11.11.4",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fontsource/playfair-display": "^5.0.19",
"@fontsource/playfair-display": "^5.0.20",
"@fontsource/poppins": "^5.0.8",
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5",
"@mui/lab": "^5.0.0-alpha.165",
"@mui/lab": "^5.0.0-alpha.166",
"@mui/material": "^5",
"@mui/x-data-grid-pro": "^6.19.4",
"@mui/x-date-pickers-pro": "^6.19.4",
"@mui/x-data-grid-pro": "^6.19.5",
"@mui/x-date-pickers-pro": "^6.19.5",
"cryptr": "^6.3.0",
"date-fns": "^3.3.1",
"graphql-request": "^6.1.0",
@ -30,15 +30,15 @@
"material-ui-popup-state": "^5.0.10",
"mui-chips-input": "^2.1.4",
"next": "14.1.0",
"next-auth": "^4.24.5",
"ra-data-graphql": "^4.16.10",
"ra-i18n-polyglot": "^4.16.10",
"ra-input-rich-text": "^4.16.10",
"ra-language-english": "^4.16.10",
"next-auth": "^4.24.6",
"ra-data-graphql": "^4.16.11",
"ra-i18n-polyglot": "^4.16.11",
"ra-input-rich-text": "^4.16.11",
"ra-language-english": "^4.16.11",
"ra-postgraphile": "^6.1.2",
"react": "18.2.0",
"react-admin": "^4.16.10",
"react-cookie": "^7.0.2",
"react-admin": "^4.16.11",
"react-cookie": "^7.1.0",
"react-digit-input": "^2.1.0",
"react-dom": "18.2.0",
"react-iframe": "^1.8.5",
@ -46,17 +46,17 @@
"react-qr-code": "^2.0.12",
"react-timer-hook": "^3.0.7",
"sharp": "^0.33.2",
"swr": "^2.2.4",
"swr": "^2.2.5",
"tss-react": "^4.9.4",
"twilio-client": "^1.15.1"
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@types/node": "^20.11.17",
"@types/react": "18.2.55",
"@types/node": "^20.11.21",
"@types/react": "18.2.60",
"@types/uuid": "^9.0.8",
"babel-loader": "^9.1.3",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-next": "^14.1.0",
"eslint-config-prettier": "^9.1.0",