[WIP] Refactoring Logics

This commit is contained in:
HeesungB
2022-12-15 15:02:50 +09:00
parent 13de62028d
commit 7de3767d03
10 changed files with 178 additions and 117 deletions
+3
View File
@@ -0,0 +1,3 @@
export const ErrorHandler = (message: string) => {
console.error(message);
};
+21
View File
@@ -1,3 +1,6 @@
import { TwitterLoginSuccess } from "../types";
import { TWITTER_LOGIN_ERROR } from "../constants/error-message";
export function request<TResponse>(
url: string,
config: RequestInit = {},
@@ -23,3 +26,21 @@ export function buildQueryString(query: Record<string, any>): string {
)
.join("&");
}
export const checkTwitterAuthQueryParameter = (
query: string,
): TwitterLoginSuccess => {
// Twitter Login Error Check
if (query.match("error")) {
throw new Error(TWITTER_LOGIN_ERROR);
}
// Twitter state, auth code check
const [, state, code] =
query.match(/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/) || [];
return {
state,
code,
};
};