From b39e89202055a0cc7b9bbe36ac724267684a31f2 Mon Sep 17 00:00:00 2001 From: Laurin Wolf Date: Mon, 16 May 2022 15:49:24 +0200 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=F0=9F=94=92=20add=20gitlab=20pag?= =?UTF-8?q?ination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/builder/pages/api/auth/[...nextauth].ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/builder/pages/api/auth/[...nextauth].ts b/apps/builder/pages/api/auth/[...nextauth].ts index 81e6608ce..84fabb214 100644 --- a/apps/builder/pages/api/auth/[...nextauth].ts +++ b/apps/builder/pages/api/auth/[...nextauth].ts @@ -126,12 +126,20 @@ const updateLastActivityDate = async (user: User) => { const getUserGroups = async (account: Account): Promise => { switch (account.provider) { case 'gitlab': { - const res = await fetch( - `${process.env.GITLAB_BASE_URL || 'https://gitlab.com'}/api/v4/groups`, - { headers: { Authorization: `Bearer ${account.access_token}` } } - ) - const userGroups = await res.json() - return userGroups.map((group: { full_path: string }) => group.full_path) + const getGitlabGroups = async (accessToken: string, page: number = 1): Promise => { + const res = await fetch( + `${process.env.GITLAB_BASE_URL || 'https://gitlab.com'}/api/v4/groups?per_page=100&page=${page}`, + { headers: { Authorization: `Bearer ${accessToken}` } } + ) + const groups: any[] = await res.json() + const nextPage = parseInt(res.headers.get('X-Next-Page') || '') + if (nextPage) { + groups.push(...await getGitlabGroups(accessToken, nextPage)) + } + return groups + } + const groups = await getGitlabGroups(account.access_token!) + return groups.map((group: { full_path: string }) => group.full_path) } default: return []