Skip to content

Commit

Permalink
feat(Auth): add sign up api
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandara-Sin committed May 10, 2023
1 parent 18ca69a commit 62bc0a5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ src/assets/video/trial_video.mov


# local env files
.env
.env.local
.env.*.local

Expand Down
18 changes: 18 additions & 0 deletions src/api/authentications/Authentication.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
14 changes: 14 additions & 0 deletions src/api/authentications/Types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import axios from "axios";

const baseURL = import.meta.env.VITE_API_URL;
const httpClient = axios.create({ baseURL });

export { httpClient };
4 changes: 3 additions & 1 deletion src/pages/authen/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -29,10 +30,11 @@ const SignIn: FC = () => {
} = useForm<IFormSignIn>({
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 (
Expand Down

0 comments on commit 62bc0a5

Please sign in to comment.