Skip to content

Commit 906dce2

Browse files
committed
Fixes for code review
1 parent 1e3440d commit 906dce2

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/app/issues/ExportModal.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ export const ExportModal = ({ onClose, initialValues }) => {
3333
AxiosResponse<string>,
3434
AxiosError,
3535
{ scopes: Scope['id'][] }
36-
>(({ scopes }) => axios.post('/api/csv/issue', { scopes }), {
37-
onSuccess: (response) => {
38-
const file = new File([response.data], 'issues.csv', {
39-
type: 'text/csv;charset=utf-8',
40-
});
41-
saveAs(file);
42-
onClose();
43-
},
44-
});
36+
>(
37+
({ scopes }) =>
38+
axios.post('/api/csv/issue', { scopes, provider: 'gitlab' }),
39+
{
40+
onSuccess: (response) => {
41+
const file = new File([response.data], 'issues.csv', {
42+
type: 'text/csv;charset=utf-8',
43+
});
44+
saveAs(file);
45+
onClose();
46+
},
47+
}
48+
);
4549

4650
const { mutate: exportToGithub, isLoading: isExportToGithubLoading } =
4751
trpc.issue.export.github.useMutation({

src/app/issues/IssueForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Scope } from '@prisma/client';
33

44
import { useFieldSelectScopeStyles } from '@/app/scopes/useFieldSelectScopeStyles';
55
import { FieldInput, FieldMultiSelect } from '@/components';
6-
import { FieldMarkdown } from '@/components/FieldMarkdown';
6+
import { FieldMarkdown } from '@/components/FieldMarkDown';
77
import { trpc } from '@/utils/trpc';
88

99
export type IssueFormProps = {

src/utils/api.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export const badRequest = (res: NextApiResponse) => {
1818
return res.status(400).end();
1919
};
2020

21-
export const notSignedIn = (res: NextApiResponse, url?: string) => {
22-
if (url && (url as string).endsWith('api/csv/issue')) {
23-
return res.status(401).json({ provider: 'gitlab' });
21+
export const notSignedIn = (res: NextApiResponse, req: NextApiRequest) => {
22+
const provider = req.body.provider;
23+
if (provider !== undefined) {
24+
return res.status(401).json({ provider: provider });
2425
}
2526

2627
return res.status(401).end();
@@ -54,10 +55,13 @@ export const apiMethods =
5455
if (!method.isPublic) {
5556
// getSession is now deprecated and is way slower than getServerSession because
5657
// it does an extra fetch out over the internet to confirm data from itself
57-
5858
const session = await getServerSession(req, res, authOptions);
59-
if (!session) {
60-
return notSignedIn(res, req.url);
59+
const provider = req.body.provider;
60+
if (
61+
!session ||
62+
session.user.accounts.find((x) => x.provider === provider) === undefined // If the user doesn't have an account logged in with the given provider.
63+
) {
64+
return notSignedIn(res, req);
6165
}
6266
}
6367

0 commit comments

Comments
 (0)