WhatsApp/Signal/Formstack/admin updates
This commit is contained in:
parent
bcecf61a46
commit
d0cc5a21de
451 changed files with 16139 additions and 39623 deletions
|
|
@ -11,6 +11,9 @@ import Google from "next-auth/providers/google";
|
|||
import Credentials from "next-auth/providers/credentials";
|
||||
import Apple from "next-auth/providers/apple";
|
||||
import AzureADProvider from "next-auth/providers/azure-ad";
|
||||
import { createLogger } from "@link-stack/logger";
|
||||
|
||||
const logger = createLogger('link-authentication');
|
||||
|
||||
const headers = { Authorization: `Token ${process.env.ZAMMAD_API_TOKEN}` };
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ const fetchRoles = async () => {
|
|||
};
|
||||
|
||||
const fetchUser = async (email: string) => {
|
||||
const url = `${process.env.ZAMMAD_URL}/api/v1/users/search?query=login:${email}&limit=1`;
|
||||
const url = `${process.env.ZAMMAD_URL}/api/v1/users/search?query=${encodeURIComponent(`login:${email}`)}&limit=1`;
|
||||
const res = await fetch(url, { headers });
|
||||
const users = await res.json();
|
||||
const user = users?.[0];
|
||||
|
|
@ -37,6 +40,9 @@ const fetchUser = async (email: string) => {
|
|||
const getUserRoles = async (email: string) => {
|
||||
try {
|
||||
const user = await fetchUser(email);
|
||||
if (!user) {
|
||||
return [];
|
||||
}
|
||||
const allRoles = await fetchRoles();
|
||||
const roles = user.role_ids.map((roleID: number) => {
|
||||
const role = allRoles[roleID];
|
||||
|
|
@ -44,7 +50,7 @@ const getUserRoles = async (email: string) => {
|
|||
});
|
||||
return roles.filter((role: string) => role !== null);
|
||||
} catch (e) {
|
||||
console.log({ e });
|
||||
logger.error({ error: e, email }, 'Failed to get user roles');
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
@ -122,6 +128,9 @@ export const authOptions: NextAuthOptions = {
|
|||
signOut: "/logout",
|
||||
},
|
||||
providers,
|
||||
session: {
|
||||
maxAge: 3 * 24 * 60 * 60,
|
||||
},
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
callbacks: {
|
||||
signIn: async ({ user }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue