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

Commit

Permalink
chore(api): use authorization instead of token for auth header
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaNecron committed Oct 2, 2021
1 parent 307fb89 commit 818e35b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
'react/react-in-jsx-scope': 'error',
'react/require-render-return': 'error',
'react/style-prop-object': 'warn',
'@next/next/no-img-element': 'off',
'react/no-find-dom-node': 'off'
'@next/next/no-img-element': 'off'
}
};
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
yarn install # or npm install
cp config.example.toml config.toml
nano config.toml # edit the config file
yarn build # or npm build
yarn build # or npm run build
yarn start # or npm start
```

Expand Down Expand Up @@ -89,7 +89,7 @@
- Discord bot

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

### Todo
- Docker support
Expand Down
4 changes: 2 additions & 2 deletions src/components/ShareXDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ShareXDialog({ open, onClose, token }) {
RequestMethod: 'POST',
RequestURL: `${apiUrl}/upload`,
Headers: {
Token: token,
Authorization: token,
Generator: generator,
PreserveFileName: preserveFileName ? 'true' : ''
},
Expand All @@ -34,7 +34,7 @@ export default function ShareXDialog({ open, onClose, token }) {
RequestMethod: 'POST',
RequestURL: `${apiUrl}/shorten`,
Headers: {
Token: token
Authorization: token
},
Body: 'FormURLEncoded',
Arguments: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Upload() {
const res = await fetch('/api/upload', {
method: 'POST',
headers: {
'Token': token,
'Authorization': token,
'Generator': generator,
'PreserveFileName': preserve ? 'true' : ''
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/shorten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import prisma from 'lib/prisma';
async function handler(req: NextApiReq, res: NextApiRes) {
if (req.method !== 'POST') return res.forbid('Invalid method');
const usr = await req.user();
if (!(req.headers.token || usr)) return res.forbid('Unauthorized');
if (!(req.headers.authorization || usr)) return res.forbid('Unauthorized');
if (!config.shortener.allow_vanity) return res.forbid('Vanity URLs are not allowed');
const user = await prisma.user.findFirst({
where: {
token: req.headers.token
token: req.headers.authorization
}
}) || usr;
if (!user) return res.forbid('Unauthorized');
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const uploader = multer({

async function handler(req: NextApiReq, res: NextApiRes) {
if (req.method !== 'POST') return res.forbid('Invalid method');
if (!req.headers.token) return res.forbid('Unauthorized');
if (!req.headers.authorization) return res.forbid('Unauthorized');
const user = await prisma.user.findFirst({
where: {
token: req.headers.token
token: req.headers.authorization
}
});
if (!user) return res.forbid('Unauthorized');
Expand Down
19 changes: 7 additions & 12 deletions src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Button, Flex, FormControl, FormErrorMessage, FormLabel, Heading, Text, useColorModeValue, useToast, VStack } from '@chakra-ui/react';
import { Box, Button, Center, FormControl, FormErrorMessage, FormLabel, Heading, Text, useColorModeValue, useToast, VStack } from '@chakra-ui/react';
import IconTextbox from 'components/IconTextbox';
import PasswordBox from 'components/PasswordBox';
import { Field, Form, Formik } from 'formik';
Expand Down Expand Up @@ -48,19 +48,14 @@ export default function Login() {
isClosable: true,
});
};
const bg = useColorModeValue('gray.100', 'gray.700');
const shadow = useColorModeValue('outline', 'dark-lg');
return (
<Flex minHeight='100vh' width='full' align='center' justifyContent='center'>
<Center h='100vh'>
<Box
p={4}
bg={bg}
width={250}
justify='flex-end'
align='center'
borderRadius={6}
boxShadow={shadow}
>
p={4}
w={300}
bg={useColorModeValue('gray.100', 'gray.700')}
boxShadow={useColorModeValue('outline', 'dark-lg')}>
<Formik initialValues={{ username: '', password: '' }} validationSchema={schema}
onSubmit={(values, actions) => onSubmit(actions, values)}
>
Expand Down Expand Up @@ -100,7 +95,7 @@ export default function Login() {
)}
</Formik>
</Box>
</Flex>
</Center>
);
}

Expand Down

0 comments on commit 818e35b

Please sign in to comment.