2
0

feat(auth): 🔒 add gitlab pagination

This commit is contained in:
Laurin Wolf
2022-05-16 15:49:24 +02:00
committed by Baptiste Arnaud
parent bda4116fbc
commit b39e892020

View File

@ -126,12 +126,20 @@ const updateLastActivityDate = async (user: User) => {
const getUserGroups = async (account: Account): Promise<string[]> => { const getUserGroups = async (account: Account): Promise<string[]> => {
switch (account.provider) { switch (account.provider) {
case 'gitlab': { case 'gitlab': {
const getGitlabGroups = async (accessToken: string, page: number = 1): Promise<any[]> => {
const res = await fetch( const res = await fetch(
`${process.env.GITLAB_BASE_URL || 'https://gitlab.com'}/api/v4/groups`, `${process.env.GITLAB_BASE_URL || 'https://gitlab.com'}/api/v4/groups?per_page=100&page=${page}`,
{ headers: { Authorization: `Bearer ${account.access_token}` } } { headers: { Authorization: `Bearer ${accessToken}` } }
) )
const userGroups = await res.json() const groups: any[] = await res.json()
return userGroups.map((group: { full_path: string }) => group.full_path) 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: default:
return [] return []