Skip to content

Commit 1b80c74

Browse files
committed
ms graph client initializer
1 parent 587be0a commit 1b80c74

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/config/auth.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MicrosoftEntraID from '@auth/core/providers/microsoft-entra-id';
2-
import { getUserDetails } from '@/services/msGraphApi';
2+
import { getUserDetails } from '@/services/msGraph';
33
import type { NextAuthConfig } from 'next-auth';
44

55
export const authConfig = {

src/services/msGraphApi.ts renamed to src/services/msGraph.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import { Client } from '@microsoft/microsoft-graph-client';
44

5-
export async function getUserDetails(accessToken: string) {
6-
// https://learn.microsoft.com/en-us/graph/sdks/create-client?tabs=typescript
7-
const client = Client.init({
5+
const initializeGraphClient = (accessToken: string) => {
6+
return Client.init({
87
authProvider: (done) => done(null, accessToken),
98
});
9+
};
10+
11+
export async function getUserDetails(accessToken: string) {
12+
const client = initializeGraphClient(accessToken);
1013
const userDetails = await client.api('/me').get();
1114
return userDetails;
1215
}

0 commit comments

Comments
 (0)