Skip to content

Commit

Permalink
chore(frontend): clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoSkorJjj committed Apr 18, 2024
1 parent 5912ff0 commit fdeed40
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 137 deletions.
10 changes: 1 addition & 9 deletions client/.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@ VITE_GOOGLE_CLIENT_ID=732452164989-t5obdqk38155erts9be9u6rg0fik7ptk.apps.googleu
VITE_STORAGE_KEY=helloworld
VITE_API_BASE_URL=http://localhost:8000
VITE_API_PROD_BASE_URL=
VITE_NODE_ENV=development

VITE_URL_ENVIRONMENT_PREFIX=test
VITE_MYINFO_CLIENT_ID=STG2-MYINFO-SELF-TEST
VITE_MYINFO_REDIRECT_URL=https://localhost:3001/callback
VITE_MYINFO_SCOPE="uinfin name email"
VITE_MYINFO_PURPOSE_ID=demonstration
VITE_MYINFO_AUTH_API_URL=https://test.api.myinfo.gov.sg/com/v4/authorize
VITE_MYINFO_METHOD=S256
VITE_NODE_ENV=development
2 changes: 0 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const PrivateRoute = lazy(() => import("~shared/routes/PrivateRoute"));
const LandingPage = lazy(() => import("~pages/landing/Landing"));
const About = lazy(() => import("~pages/about/About"));
const LoginPage = lazy(() => import("~pages/auth/Login"));
const MyInfoCallbackPage = lazy(() => import("~pages/auth/MyInfoCallback"));
const SgIDCallbackPage = lazy(() => import("~pages/auth/SgIDCallback"));

// Private Page
Expand Down Expand Up @@ -71,7 +70,6 @@ const App = () => {
>
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/callback" element={<MyInfoCallbackPage />} />
<Route
path="/auth/sgid/callback"
element={<SgIDCallbackPage />}
Expand Down
1 change: 0 additions & 1 deletion client/src/config/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions client/src/config/myInfo_config.ts

This file was deleted.

67 changes: 0 additions & 67 deletions client/src/features/auth/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useGoogleLogin } from "@react-oauth/google";
import useAuthStore from "~shared/store/AuthStore";

import { api, handleResponse } from "~api";
import { MYINFO_CONFIG } from "~config";
import { AuthContextType } from "~types/auth";

const AuthContext = createContext<AuthContextType | undefined>(undefined);
Expand Down Expand Up @@ -67,70 +66,6 @@ const useProvideAuth = (): AuthContextType => {
flow: "auth-code",
});

const myInfoGetCode = async (): Promise<void> => {
try {
const response = await api.post(
"/api/v1/auth/myInfo/generateCodeChallenge",
);
const result = response.data.code_challenge;
const MYINFO_UNIQUE_ID = response.headers["x-myinfo-unique-id"];

authFlow(MYINFO_UNIQUE_ID);

const authorizeUrl =
MYINFO_CONFIG.MYINFO_AUTH_API_URL +
"?client_id=" +
MYINFO_CONFIG.MYINFO_CLIENT_ID +
"&scope=" +
MYINFO_CONFIG.MYINFO_SCOPES +
"&purpose_id=" +
MYINFO_CONFIG.MYINFO_PURPOSE_ID +
"&code_challenge=" +
result +
"&code_challenge_method=" +
MYINFO_CONFIG.MYINFO_METHOD +
"&redirect_uri=" +
MYINFO_CONFIG.MYINFO_CALLBACK_URL;

window.location.href = authorizeUrl;
} catch (error) {
console.log(error);
}
};

const myInfoAuth = async (): Promise<void> => {
try {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");

if (!code) {
console.error("Auth code is required");
return;
}

const response = await api.post(
"/api/v1/auth/myInfo/callback",
{
code: code,
},
{
headers: {
Authorization: `Bearer ${authorization}`,
},
},
);
const AUTHORIZATION_TOKEN = response.headers["x-access-token"];

const data = await handleResponse(response);
const userData = JSON.parse(data.payload.value);

login(userData, AUTHORIZATION_TOKEN);
navigate("/");
} catch (error) {
console.log(error);
}
};

const sgIdGetAuthUrl = async (): Promise<void> => {
try {
const response = await api.post("/api/v1/auth/sgId/generateAuthUrl");
Expand Down Expand Up @@ -241,8 +176,6 @@ const useProvideAuth = (): AuthContextType => {
user,
authorization,
googleAuth,
myInfoGetCode,
myInfoAuth,
sgIdGetAuthUrl,
sgIdAuth,
signOut,
Expand Down
9 changes: 0 additions & 9 deletions client/src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Text,
} from "@chakra-ui/react";

// import MyInfoLogo from "~assets/img/singpass/Primary@2x.png";
import SgIDLogo from "~assets/img/singpass/sgid_logo.png";
import SingPassLogo from "~assets/img/singpass/singpass_logo_fullcolours-1.png";

Expand Down Expand Up @@ -64,14 +63,6 @@ const LoginPage = () => {
rightIcon={<Image src={SgIDLogo} boxSize="60px" height="30px" />}
onClick={sgIdGetAuthUrl}
/>
{/* <IconButton
aria-label="myinfo"
border="none"
size="lg"
icon={<Image src={MyInfoLogo} boxSize="100%" objectFit="cover" />}
onClick={myInfoGetCode}
w={{ base: "full", sm: "80%" }}
/> */}
</Stack>
</Box>
</Stack>
Expand Down
26 changes: 0 additions & 26 deletions client/src/pages/auth/MyInfoCallback.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions client/src/shared/types/auth/AuthContextType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export type AuthContextType = {
user: UserData | null;
authorization: string | null;
googleAuth: () => void;
myInfoGetCode: () => void;
myInfoAuth: () => void;
sgIdGetAuthUrl: () => void;
sgIdAuth: () => void;
signOut: () => void;
Expand Down
6 changes: 0 additions & 6 deletions client/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ interface ImportMetaEnv {
readonly VITE_LOCATIONIQ_ACCESS_TOKEN: string;
readonly VITE_STORAGE_KEY: string;
readonly VITE_URL_ENVIRONMENT_PREFIX: string;
readonly VITE_MYINFO_CLIENT_ID: string;
readonly VITE_MYINFO_REDIRECT_URL: string;
readonly VITE_MYINFO_SCOPE: string;
readonly VITE_MYINFO_PURPOSE_ID: string;
readonly VITE_MYINFO_AUTH_API_URL: string;
readonly VITE_MYINFO_METHOD: string;
readonly VITE_UNSPLASH_CLIENT_ID: string;
}

Expand Down
1 change: 0 additions & 1 deletion client/tsconfig.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"baseUrl": "./",
"paths": {
"~components/*": ["./src/components/*"],
"~config": ["./src/config"],
"~pages/*": ["./src/pages/*"],
"~shared/*": ["./src/shared/*"],
"~util": ["./src/shared/util"],
Expand Down
1 change: 0 additions & 1 deletion client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default defineConfig({
resolve: {
alias: {
"~pages": path.resolve(__dirname, "src/pages"),
"~config": path.resolve(__dirname, "src/config"),
"~components": path.resolve(__dirname, "src/components"),
"~shared": path.resolve(__dirname, "src/shared"),
"~util": path.resolve(__dirname, "src/shared/util"),
Expand Down

0 comments on commit fdeed40

Please sign in to comment.