feat: git login

This commit is contained in:
archer
2023-08-07 17:19:04 +08:00
parent 206eb81bb4
commit ce729dff1f
12 changed files with 310 additions and 32 deletions

View File

@@ -1,11 +1,14 @@
import React, { useState, Dispatch, useCallback } from 'react';
import { FormControl, Flex, Input, Button, FormErrorMessage, Box } from '@chakra-ui/react';
import { useForm } from 'react-hook-form';
import { useRouter } from 'next/router';
import { PageTypeEnum } from '@/constants/user';
import { postLogin } from '@/api/user';
import type { ResLogin } from '@/api/response/user';
import { useToast } from '@/hooks/useToast';
import { feConfigs } from '@/store/static';
import { useGlobalStore } from '@/store/global';
import MyIcon from '@/components/Icon';
interface Props {
setPageType: Dispatch<`${PageTypeEnum}`>;
@@ -18,7 +21,10 @@ interface LoginFormType {
}
const LoginForm = ({ setPageType, loginSuccess }: Props) => {
const router = useRouter();
const { lastRoute = '/app/list' } = router.query as { lastRoute: string };
const { toast } = useToast();
const { setLoginStore } = useGlobalStore();
const {
register,
handleSubmit,
@@ -52,6 +58,19 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
[loginSuccess, toast]
);
const onclickGit = useCallback(() => {
setLoginStore({
provider: 'git',
lastRoute
});
router.replace(
`https://github.com/login/oauth/authorize?client_id=${
feConfigs?.gitLoginKey
}&redirect_uri=${`${location.origin}/login/provider`}&scope=user:email%20read:user`,
'_self'
);
}, [lastRoute, setLoginStore]);
return (
<>
<Box fontWeight={'bold'} fontSize={'2xl'} textAlign={'center'}>
@@ -117,6 +136,17 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
>
</Button>
{feConfigs?.show_register && (
<Flex mt={10} justifyContent={'center'} alignItems={'center'}>
<MyIcon
name="gitFill"
w={'34px'}
cursor={'pointer'}
color={'myGray.800'}
onClick={onclickGit}
/>
</Flex>
)}
</form>
</>
);