👔 create callback forwader
create a handler to forward callback requests from the OAuth provider to the main backend system.
This commit is contained in:
@ -1,9 +1,8 @@
|
|||||||
import OauthCallbackHandler from "@/features/oauth-callback/pages/callbackHandler";
|
import OauthCallbackHandler from "@/features/oauth-callback/pages/callbackHandler";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ParamProps } from "@/features/oauth-callback/types/ParamProps";
|
|
||||||
|
|
||||||
const page = ({ params, searchParams }: ParamProps) => {
|
const page = () => {
|
||||||
return <OauthCallbackHandler callbackData={{ params, searchParams }} />;
|
return <OauthCallbackHandler />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default page;
|
export default page;
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { api } from "@/shared/api/connector";
|
import { api } from "@/shared/api/connector";
|
||||||
|
|
||||||
export const SendCallbackToServer = async (data: Record<string, any>) => {
|
export const SendCallbackToServer = async (data: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get("auth/google/callback", {
|
const response = await api.get(`auth/google/callback${data}`);
|
||||||
searchParams: { ...data },
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
console.log(result);
|
|
||||||
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending callback to server:", error);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ParamProps } from "../types/ParamProps";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import SecurityCheckup from "@/shared/auth/ui/SecurityCheckup";
|
import SecurityCheckup from "@/shared/auth/ui/SecurityCheckup";
|
||||||
import SecurityCheckupFailed from "@/shared/auth/ui/SecurityCheckupFailed";
|
import SecurityCheckupFailed from "@/shared/auth/ui/SecurityCheckupFailed";
|
||||||
import LoadingProcess from "../ui/LoadingProcess";
|
import LoadingProcess from "../ui/LoadingProcess";
|
||||||
|
|
||||||
const OauthCallbackHandler = ({
|
const OauthCallbackHandler = () => {
|
||||||
callbackData,
|
|
||||||
}: {
|
|
||||||
callbackData: ParamProps;
|
|
||||||
}) => {
|
|
||||||
/**
|
/**
|
||||||
* Create a lit component that will be used in popp, consisting of 3 component flows:
|
* Create a lit component that will be used in popp, consisting of 3 component flows:
|
||||||
* 1. When the user opens it, a browser environment check will be performed.
|
* 1. When the user opens it, a browser environment check will be performed.
|
||||||
@ -21,7 +16,7 @@ const OauthCallbackHandler = ({
|
|||||||
const componentFlowList = {
|
const componentFlowList = {
|
||||||
securityCheckup: <SecurityCheckup />,
|
securityCheckup: <SecurityCheckup />,
|
||||||
securityCheckupFailed: <SecurityCheckupFailed />,
|
securityCheckupFailed: <SecurityCheckupFailed />,
|
||||||
proceedCallback: <LoadingProcess callbackData={callbackData} />,
|
proceedCallback: <LoadingProcess />,
|
||||||
};
|
};
|
||||||
|
|
||||||
// State to set the current page component
|
// State to set the current page component
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
export interface ParamProps {
|
export interface ParamProps {
|
||||||
params: { provider: string[] };
|
params: { provider: string[] };
|
||||||
searchParams: { [key: string]: string | string[] | undefined };
|
searchParams:
|
||||||
|
| string
|
||||||
|
| string[][]
|
||||||
|
| Record<string, string>
|
||||||
|
| URLSearchParams
|
||||||
|
| undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,21 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { CircularProgress } from "@heroui/react";
|
import { CircularProgress } from "@heroui/react";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
import { ParamProps } from "../types/ParamProps";
|
|
||||||
import { SendCallbackToServer } from "../lib/sendCallbackToServer";
|
import { SendCallbackToServer } from "../lib/sendCallbackToServer";
|
||||||
|
|
||||||
const LoadingProcess = ({ callbackData }: { callbackData: ParamProps }) => {
|
const LoadingProcess = () => {
|
||||||
|
const calledRef = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (calledRef.current) return;
|
||||||
|
calledRef.current = true;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await SendCallbackToServer(callbackData);
|
await SendCallbackToServer(window.location.search);
|
||||||
console.log(
|
window.close();
|
||||||
`Callback data sent to server successfully: ${JSON.stringify(
|
|
||||||
response
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error during loading process:", error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
@ -28,9 +27,6 @@ const LoadingProcess = ({ callbackData }: { callbackData: ParamProps }) => {
|
|||||||
<p className="text-sm text-neutral-400">
|
<p className="text-sm text-neutral-400">
|
||||||
Your request is being processed
|
Your request is being processed
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-neutral-400">
|
|
||||||
{JSON.stringify(callbackData)}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,4 +8,5 @@ export const api = ky.create({
|
|||||||
headers: {
|
headers: {
|
||||||
access_token: process.env.MAIN_BACKEND_API_KEY,
|
access_token: process.env.MAIN_BACKEND_API_KEY,
|
||||||
},
|
},
|
||||||
|
retry: 0,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user