Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 818e35b

Browse files
committed
chore(api): use authorization instead of token for auth header
1 parent 307fb89 commit 818e35b

File tree

7 files changed

+17
-23
lines changed

7 files changed

+17
-23
lines changed

.eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = {
1919
'react/react-in-jsx-scope': 'error',
2020
'react/require-render-return': 'error',
2121
'react/style-prop-object': 'warn',
22-
'@next/next/no-img-element': 'off',
23-
'react/no-find-dom-node': 'off'
22+
'@next/next/no-img-element': 'off'
2423
}
2524
};

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
yarn install # or npm install
2323
cp config.example.toml config.toml
2424
nano config.toml # edit the config file
25-
yarn build # or npm build
25+
yarn build # or npm run build
2626
yarn start # or npm start
2727
```
2828

@@ -89,7 +89,7 @@
8989
- Discord bot
9090

9191
### Contribution
92-
- All contribution must be made in `dev` branch, other contributions in `v0` will be rejected.
92+
- All contribution must be made in `dev` branch, contributions in `v0` will be closed.
9393

9494
### Todo
9595
- Docker support

src/components/ShareXDialog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function ShareXDialog({ open, onClose, token }) {
1616
RequestMethod: 'POST',
1717
RequestURL: `${apiUrl}/upload`,
1818
Headers: {
19-
Token: token,
19+
Authorization: token,
2020
Generator: generator,
2121
PreserveFileName: preserveFileName ? 'true' : ''
2222
},
@@ -34,7 +34,7 @@ export default function ShareXDialog({ open, onClose, token }) {
3434
RequestMethod: 'POST',
3535
RequestURL: `${apiUrl}/shorten`,
3636
Headers: {
37-
Token: token
37+
Authorization: token
3838
},
3939
Body: 'FormURLEncoded',
4040
Arguments: {

src/components/pages/Upload.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function Upload() {
2929
const res = await fetch('/api/upload', {
3030
method: 'POST',
3131
headers: {
32-
'Token': token,
32+
'Authorization': token,
3333
'Generator': generator,
3434
'PreserveFileName': preserve ? 'true' : ''
3535
},

src/pages/api/shorten.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import prisma from 'lib/prisma';
77
async function handler(req: NextApiReq, res: NextApiRes) {
88
if (req.method !== 'POST') return res.forbid('Invalid method');
99
const usr = await req.user();
10-
if (!(req.headers.token || usr)) return res.forbid('Unauthorized');
10+
if (!(req.headers.authorization || usr)) return res.forbid('Unauthorized');
1111
if (!config.shortener.allow_vanity) return res.forbid('Vanity URLs are not allowed');
1212
const user = await prisma.user.findFirst({
1313
where: {
14-
token: req.headers.token
14+
token: req.headers.authorization
1515
}
1616
}) || usr;
1717
if (!user) return res.forbid('Unauthorized');

src/pages/api/upload.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const uploader = multer({
1414

1515
async function handler(req: NextApiReq, res: NextApiRes) {
1616
if (req.method !== 'POST') return res.forbid('Invalid method');
17-
if (!req.headers.token) return res.forbid('Unauthorized');
17+
if (!req.headers.authorization) return res.forbid('Unauthorized');
1818
const user = await prisma.user.findFirst({
1919
where: {
20-
token: req.headers.token
20+
token: req.headers.authorization
2121
}
2222
});
2323
if (!user) return res.forbid('Unauthorized');

src/pages/auth/login.tsx

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Button, Flex, FormControl, FormErrorMessage, FormLabel, Heading, Text, useColorModeValue, useToast, VStack } from '@chakra-ui/react';
1+
import { Box, Button, Center, FormControl, FormErrorMessage, FormLabel, Heading, Text, useColorModeValue, useToast, VStack } from '@chakra-ui/react';
22
import IconTextbox from 'components/IconTextbox';
33
import PasswordBox from 'components/PasswordBox';
44
import { Field, Form, Formik } from 'formik';
@@ -48,19 +48,14 @@ export default function Login() {
4848
isClosable: true,
4949
});
5050
};
51-
const bg = useColorModeValue('gray.100', 'gray.700');
52-
const shadow = useColorModeValue('outline', 'dark-lg');
5351
return (
54-
<Flex minHeight='100vh' width='full' align='center' justifyContent='center'>
52+
<Center h='100vh'>
5553
<Box
56-
p={4}
57-
bg={bg}
58-
width={250}
59-
justify='flex-end'
60-
align='center'
6154
borderRadius={6}
62-
boxShadow={shadow}
63-
>
55+
p={4}
56+
w={300}
57+
bg={useColorModeValue('gray.100', 'gray.700')}
58+
boxShadow={useColorModeValue('outline', 'dark-lg')}>
6459
<Formik initialValues={{ username: '', password: '' }} validationSchema={schema}
6560
onSubmit={(values, actions) => onSubmit(actions, values)}
6661
>
@@ -100,7 +95,7 @@ export default function Login() {
10095
)}
10196
</Formik>
10297
</Box>
103-
</Flex>
98+
</Center>
10499
);
105100
}
106101

0 commit comments

Comments
 (0)