Skip to content

Commit

Permalink
fix: 🎨 Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 30, 2022
1 parent 3db753e commit fe26e89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
44 changes: 24 additions & 20 deletions apps/builder/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ if (
process.env.NEXT_PUBLIC_GITLAB_CLIENT_ID &&
process.env.GITLAB_CLIENT_SECRET
) {
const BASE_URL = process.env.NEXT_PUBLIC_GITLAB_BASE_URL || 'gitlab.com'
providers.push(GitlabProvider({
clientId: process.env.NEXT_PUBLIC_GITLAB_CLIENT_ID,
clientSecret: process.env.GITLAB_CLIENT_SECRET,
authorization: `${BASE_URL}/oauth/authorize?scope=read_api`,
token: `${BASE_URL}/oauth/token`,
userinfo: `${BASE_URL}/api/v4/user`,
}))
const BASE_URL = process.env.GITLAB_BASE_URL || 'https://gitlab.com'
providers.push(
GitlabProvider({
clientId: process.env.NEXT_PUBLIC_GITLAB_CLIENT_ID,
clientSecret: process.env.GITLAB_CLIENT_SECRET,
authorization: `${BASE_URL}/oauth/authorize?scope=read_api`,
token: `${BASE_URL}/oauth/token`,
userinfo: `${BASE_URL}/api/v4/user`,
})
)
}

const handler = (req: NextApiRequest, res: NextApiResponse) => {
Expand Down Expand Up @@ -121,29 +123,31 @@ const updateLastActivityDate = async (user: User) => {
})
}

async function getUserGroups(account: Account): Promise<string[]> {
const getUserGroups = async (account: Account): Promise<string[]> => {
switch (account.provider) {
case 'gitlab': {
const res = await fetch(
`${process.env.NEXT_PUBLIC_GITLAB_BASE_URL || 'gitlab.com'}/api/v4/groups`,
{ headers: { 'Authorization': `Bearer ${account.access_token}` } },
`${process.env.GITLAB_BASE_URL || 'https://gitlab.com'}/api/v4/groups`,
{ headers: { Authorization: `Bearer ${account.access_token}` } }
)
const userGroups: string[] = (await res.json())
return userGroups.map((group: any) => group.full_path)
const userGroups = await res.json()
return userGroups.map((group: { full_path: string }) => group.full_path)
}
default: return []
default:
return []
}
}

function getRequiredGroups(provider: string): string[] {
const getRequiredGroups = (provider: string): string[] => {
switch (provider) {
case 'gitlab': return process.env.GITLAB_REQUIRED_GROUPS?.split(',') || []
default: return []
case 'gitlab':
return process.env.GITLAB_REQUIRED_GROUPS?.split(',') || []
default:
return []
}
}

function checkHasGroups(userGroups: string[], requiredGroups: string[]) {
return userGroups?.some(userGroup => requiredGroups?.includes(userGroup))
}
const checkHasGroups = (userGroups: string[], requiredGroups: string[]) =>
userGroups?.some((userGroup) => requiredGroups?.includes(userGroup))

export default withSentry(handler)
14 changes: 7 additions & 7 deletions apps/docs/docs/self-hosting/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ Used for authenticating with GitLab.
Follow the official GitLab guide for creating OAuth2 applications [here](https://docs.gitlab.com/ee/integration/oauth_provider.html).
The Authorization callback URL should be `$NEXTAUTH_URL/api/auth/callback/gitlab`

| Parameter | Default | Description |
| ---------------------------- | ------- | -------------------------------------------------------------------------------------|
| NEXT_PUBLIC_GITLAB_CLIENT_ID | -- | Application client ID. Also used to check if it is enabled in the front-end |
| GITLAB_CLIENT_SECRET | -- | Application secret |
| NEXT_PUBLIC_GITLAB_BASE_URL | -- | Base URL of the GitLab instance, e.g. `https://gitlab.com` |
| NEXT_PUBLIC_GITLAB_NAME | -- | Name of the GitLab instance, used for the SSO Login Button, e.g. `GitLab` |
| GITLAB_REQUIRED_GROUPS | -- | Comma-separated list of groups the user has to be a direct member of, e.g. `foo,bar` |
| Parameter | Default | Description |
| ---------------------------- | ------------------ | ------------------------------------------------------------------------------------ | --- |
| NEXT_PUBLIC_GITLAB_CLIENT_ID | -- | Application client ID. Also used to check if it is enabled in the front-end |
| GITLAB_CLIENT_SECRET | -- | Application secret |
| GITLAB_BASE_URL | https://gitlab.com | Base URL of the GitLab instance | |
| GITLAB_REQUIRED_GROUPS | -- | Comma-separated list of groups the user has to be a direct member of, e.g. `foo,bar` |
| NEXT_PUBLIC_GITLAB_NAME | GitLab | Name of the GitLab instance, used for the SSO Login Button |

</p></details>

Expand Down

0 comments on commit fe26e89

Please sign in to comment.