mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
chore: application prettier
This commit is contained in:
@ -11,13 +11,13 @@ const options = {
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' }
|
||||
password: { label: 'Password', type: 'password' },
|
||||
},
|
||||
authorize: async (credentials, req) => {
|
||||
try {
|
||||
const data = {
|
||||
email: credentials.email,
|
||||
password: credentials.password
|
||||
password: credentials.password,
|
||||
};
|
||||
|
||||
const user = await getJWT(data);
|
||||
@ -28,11 +28,11 @@ const options = {
|
||||
} catch (error) {
|
||||
throw new Error(error.message || 'Invalid credentials');
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
}),
|
||||
],
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
strategy: 'jwt',
|
||||
maxAge: 30 * 24 * 60 * 60, // 30 jours
|
||||
updateAge: 24 * 60 * 60, // 24 heures
|
||||
},
|
||||
@ -43,9 +43,9 @@ const options = {
|
||||
httpOnly: true,
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
secure: process.env.NODE_ENV === 'production'
|
||||
}
|
||||
}
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
},
|
||||
},
|
||||
},
|
||||
callbacks: {
|
||||
async jwt({ token, user }) {
|
||||
@ -55,7 +55,7 @@ const options = {
|
||||
...token,
|
||||
token: user.token,
|
||||
refresh: user.refresh,
|
||||
tokenExpires: jwt_decode.decode(user.token).exp * 1000
|
||||
tokenExpires: jwt_decode.decode(user.token).exp * 1000,
|
||||
};
|
||||
}
|
||||
|
||||
@ -69,23 +69,23 @@ const options = {
|
||||
const response = await refreshJWT({ refresh: token.refresh });
|
||||
if (response && response?.token) {
|
||||
return {
|
||||
...token,
|
||||
token: response.token,
|
||||
refresh: response.refresh,
|
||||
tokenExpires: jwt_decode.decode(response.token).exp * 1000
|
||||
};
|
||||
}
|
||||
else{
|
||||
...token,
|
||||
token: response.token,
|
||||
refresh: response.refresh,
|
||||
tokenExpires: jwt_decode.decode(response.token).exp * 1000,
|
||||
};
|
||||
} else {
|
||||
throw new Error('Failed to refresh token');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Refresh token failed:", error);
|
||||
logger.error('Refresh token failed:', error);
|
||||
return token;
|
||||
}
|
||||
},
|
||||
async session({ session, token }) {
|
||||
if (token && token?.token) {
|
||||
const { user_id, email, roles, roleIndexLoginDefault } = jwt_decode.decode(token.token);
|
||||
const { user_id, email, roles, roleIndexLoginDefault } =
|
||||
jwt_decode.decode(token.token);
|
||||
session.user = {
|
||||
...session.user,
|
||||
token: token.token,
|
||||
@ -93,16 +93,16 @@ const options = {
|
||||
user_id: user_id,
|
||||
email: email,
|
||||
roles: roles,
|
||||
roleIndexLoginDefault : roleIndexLoginDefault
|
||||
roleIndexLoginDefault: roleIndexLoginDefault,
|
||||
};
|
||||
}
|
||||
return session;
|
||||
}
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: '/[locale]/users/login'
|
||||
signIn: '/[locale]/users/login',
|
||||
},
|
||||
csrf: true
|
||||
csrf: true,
|
||||
};
|
||||
|
||||
export default (req, res) => NextAuth(req, res, options);
|
||||
export default (req, res) => NextAuth(req, res, options);
|
||||
|
||||
@ -8,30 +8,32 @@ export default function handler(req, res) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
templateId,
|
||||
email,
|
||||
is_required
|
||||
is_required,
|
||||
}),
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
return response.json().then((err) => {
|
||||
throw new Error(err.message);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(err => { throw new Error(err.message); });
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Template cloned successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error cloning template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
.then((data) => {
|
||||
console.log('Template cloned successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error cloning template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
} else {
|
||||
res.setHeader('Allow', ['POST']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,30 +3,32 @@ import { BE_DOCUSEAL_DOWNLOAD_TEMPLATE } from '@/utils/Url';
|
||||
export default function handler(req, res) {
|
||||
if (req.method === 'GET') {
|
||||
const { slug } = req.query;
|
||||
console.log('slug : ', slug)
|
||||
console.log('slug : ', slug);
|
||||
|
||||
fetch(`${BE_DOCUSEAL_DOWNLOAD_TEMPLATE}/${slug}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY
|
||||
}
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY,
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(err => { throw new Error(err.message); });
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Template downloaded successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error downloading template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
return response.json().then((err) => {
|
||||
throw new Error(err.message);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('Template downloaded successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error downloading template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
} else {
|
||||
res.setHeader('Allow', ['GET']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,24 +6,26 @@ export default function handler(req, res) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(req.body),
|
||||
})
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
return response.json().then(data => ({ status: response.status, data }));
|
||||
})
|
||||
.then(({ status, data }) => {
|
||||
console.log('Response data:', data);
|
||||
res.status(status).json(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
.then((response) => {
|
||||
console.log('Response status:', response.status);
|
||||
return response
|
||||
.json()
|
||||
.then((data) => ({ status: response.status, data }));
|
||||
})
|
||||
.then(({ status, data }) => {
|
||||
console.log('Response data:', data);
|
||||
res.status(status).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
} else {
|
||||
res.setHeader('Allow', ['POST']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,25 +7,27 @@ export default function handler(req, res) {
|
||||
fetch(`${BE_DOCUSEAL_REMOVE_TEMPLATE}/${templateId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY
|
||||
}
|
||||
'X-Auth-Token': process.env.DOCUSEAL_API_KEY,
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(err => { throw new Error(err.message); });
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Template removed successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error removing template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
return response.json().then((err) => {
|
||||
throw new Error(err.message);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('Template removed successfully:', data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error removing template:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
});
|
||||
} else {
|
||||
res.setHeader('Allow', ['DELETE']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user