diff --git a/src/app/auth/LoginForm.tsx b/src/app/auth/LoginForm.tsx
index 25f8e6a..37ab510 100644
--- a/src/app/auth/LoginForm.tsx
+++ b/src/app/auth/LoginForm.tsx
@@ -1,38 +1,75 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import { Box, Button, Stack, Text } from '@chakra-ui/react';
import { signIn } from 'next-auth/react';
import { useTranslation } from 'react-i18next';
-import { FiGithub, FiInfo } from 'react-icons/fi';
+import { FiGithub, FiGitlab, FiInfo } from 'react-icons/fi';
import { Icon } from '@/components';
-export const LoginForm = ({ onSuccess = () => undefined, ...rest }: TODO) => {
+export const LoginForm = ({
+ onSuccess = () => undefined,
+ provider,
+ ...rest
+}: TODO) => {
const { t } = useTranslation();
+ useEffect(() => {
+ if (provider === undefined) {
+ provider = 'github';
+ }
+ }, []);
return (
-
- }
- ms="auto"
- onClick={() => signIn('github')}
- >
- {t('auth:login.actions.github.login')}
-
-
-
- Only users from{' '}
-
- {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS}
- {' '}
- GitHub organisation(s) will be able to use the application once logged
- in.
-
-
-
+ <>
+ {provider === 'github' ? (
+
+ }
+ ms="auto"
+ onClick={() => signIn('github')}
+ >
+ {t('auth:login.actions.github.login')}
+
+
+
+ Only users from{' '}
+
+ {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS}
+ {' '}
+ GitHub organisation(s) will be able to use the application once
+ logged in.
+
+
+
+ ) : (
+
+ }
+ ms="auto"
+ onClick={() => signIn('gitlab')}
+ >
+ {t('auth:login.actions.gitlab.login')}
+
+
+
+ Only users from{' '}
+
+ {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS}
+ {' '}
+ GitLab organisation(s) will be able to use the application once
+ logged in.
+
+
+
+ )}
+ >
);
};
diff --git a/src/app/auth/LoginModalInterceptor.tsx b/src/app/auth/LoginModalInterceptor.tsx
index f10562e..380703f 100644
--- a/src/app/auth/LoginModalInterceptor.tsx
+++ b/src/app/auth/LoginModalInterceptor.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useRef } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import {
Heading,
@@ -28,6 +28,8 @@ export const LoginModalInterceptor = () => {
const pathnameRef = useRef(pathname);
pathnameRef.current = pathname;
+ const [provider, setProvider] = useState('github');
+
useEffect(() => {
const interceptor = Axios.interceptors.response.use(
(r) => r,
@@ -36,6 +38,10 @@ export const LoginModalInterceptor = () => {
error?.response?.status === 401 &&
pathnameRef.current !== '/login'
) {
+ if (error.response.data && error.response.data.provider) {
+ setProvider(error.response.data.provider);
+ }
+
queryCache.cancelQueries();
onOpen();
}
@@ -76,7 +82,7 @@ export const LoginModalInterceptor = () => {
{t('auth:interceptor.title')}
{t('auth:interceptor.description')}
-
+
diff --git a/src/utils/api.ts b/src/utils/api.ts
index 76f87a3..03bc8c7 100644
--- a/src/utils/api.ts
+++ b/src/utils/api.ts
@@ -18,7 +18,11 @@ export const badRequest = (res: NextApiResponse) => {
return res.status(400).end();
};
-export const notSignedIn = (res: NextApiResponse) => {
+export const notSignedIn = (res: NextApiResponse, url?: string) => {
+ if (url && (url as string).endsWith('api/csv/issue')) {
+ return res.status(401).json({ provider: 'gitlab' });
+ }
+
return res.status(401).end();
};
@@ -50,10 +54,10 @@ export const apiMethods =
if (!method.isPublic) {
// getSession is now deprecated and is way slower than getServerSession because
// it does an extra fetch out over the internet to confirm data from itself
- const session = await getServerSession(req, res, authOptions);
+ const session = await getServerSession(req, res, authOptions);
if (!session) {
- return notSignedIn(res);
+ return notSignedIn(res, req.url);
}
}