Agenda Sync refactor Mig Graph

This commit is contained in:
alma 2026-01-14 16:24:52 +01:00
parent c859068e87
commit dbbc2ff59a

View File

@ -17,8 +17,21 @@ const GRAPH_API_BASE = 'https://graph.microsoft.com/v1.0';
* Get a configured Axios instance for Microsoft Graph API
*/
async function getMicrosoftGraphClient(mailCredentialId: string): Promise<AxiosInstance> {
// Get fresh access token
const tokenResult = await ensureFreshToken(mailCredentialId);
// Look up the mail credential to get userId and email for token refresh
const account = await prisma.mailCredentials.findUnique({
where: { id: mailCredentialId },
select: {
userId: true,
email: true,
},
});
if (!account) {
throw new Error('Mail credential not found for Microsoft Graph client');
}
// Get fresh access token using userId + email
const tokenResult = await ensureFreshToken(account.userId, account.email);
if (!tokenResult || !tokenResult.accessToken) {
throw new Error('Failed to obtain valid access token for Microsoft Graph API. The account may need to be re-authenticated with Mail.Read and Mail.Send permissions.');