diff --git a/.gitignore b/.gitignore index d11a175..baba6e8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ src/assets/video/trial_video.mov # local env files +.env .env.local .env.*.local diff --git a/src/api/authentications/Authentication.ts b/src/api/authentications/Authentication.ts new file mode 100644 index 0000000..b0e2f3a --- /dev/null +++ b/src/api/authentications/Authentication.ts @@ -0,0 +1,18 @@ +import { httpClient } from "../client"; +import { ISignUpBody, ISignUpRes } from "./Types"; + +const header = { "X-API-Key": import.meta.env.VITE_API_PUBLIC_KEY ?? "" }; + +export const signUp = (body: ISignUpBody) => + new Promise((resolve: (value: ISignUpRes) => void, reject) => { + httpClient + .post("/oauth/signup", body, { + headers: header, + }) + .then(({ data }) => { + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); diff --git a/src/api/authentications/Types.ts b/src/api/authentications/Types.ts new file mode 100644 index 0000000..e8088f8 --- /dev/null +++ b/src/api/authentications/Types.ts @@ -0,0 +1,14 @@ +type TTokenType = "Bearer" | "ID"; + +type TGrantType = "auth_code" | "verify_code"; + +export interface ISignUpRes { + auth_code: string; + access_token: string; + token_type: TTokenType; +} + +export interface ISignUpBody { + email: string; + grant_type: TGrantType; +} diff --git a/src/api/client.ts b/src/api/client.ts new file mode 100644 index 0000000..bfcfab2 --- /dev/null +++ b/src/api/client.ts @@ -0,0 +1,6 @@ +import axios from "axios"; + +const baseURL = import.meta.env.VITE_API_URL; +const httpClient = axios.create({ baseURL }); + +export { httpClient }; diff --git a/src/pages/authen/SignIn.tsx b/src/pages/authen/SignIn.tsx index 8260f6b..ad52e6c 100644 --- a/src/pages/authen/SignIn.tsx +++ b/src/pages/authen/SignIn.tsx @@ -18,6 +18,7 @@ import { import { AutoAwesomeRounded } from "@mui/icons-material"; import GoogleLogo from "../../assets/icon/google-logo"; import GitHubLogo from "../../assets/icon/github-logo"; +import { signUp } from "../../api/authentications/Authentication"; const SignIn: FC = () => { const { signIn } = useAuth(); @@ -29,10 +30,11 @@ const SignIn: FC = () => { } = useForm({ resolver: yupResolver(signInSchema), }); - const onSubmit = (data: IFormSignIn) => { + const onSubmit = async ({ email }: IFormSignIn) => { const next = () => { navigate("/browse-connect", { replace: true }); }; + await signUp({ grant_type: "auth_code", email }); signIn("member", next); }; return (