👔 add oauth callback handler
This commit is contained in:
@ -4,16 +4,26 @@ import { api } from "@/shared/api/connector";
|
||||
import { redirect } from "next/navigation";
|
||||
import { ResponseRequestOauthUrl } from "../types/responseRequestOauthUrl";
|
||||
|
||||
const requestOauthUrl = async (requestEndpoint: string) => {
|
||||
const requestOauthUrl = async (providerData: {
|
||||
name: string;
|
||||
endpoint: string;
|
||||
}) => {
|
||||
// Check if requestEndpoint is provided, if not throw an error
|
||||
if (!requestEndpoint) throw new Error("oAuth endpoint request not found");
|
||||
if (!providerData.endpoint)
|
||||
throw new Error("oAuth endpoint request not found");
|
||||
|
||||
// Define a variable to hold the OAuth data
|
||||
let oauthData: Promise<ResponseRequestOauthUrl>;
|
||||
|
||||
// Fetch OAuth data from the API
|
||||
try {
|
||||
const response = await api.get(requestEndpoint);
|
||||
const response = await api.get(providerData.endpoint, {
|
||||
searchParams: {
|
||||
callback: `${
|
||||
process.env.APP_DOMAIN
|
||||
}/auth/callback/${providerData.name.toLocaleLowerCase()}`,
|
||||
},
|
||||
});
|
||||
oauthData = response.json<ResponseRequestOauthUrl>();
|
||||
} catch (error) {
|
||||
throw new Error(JSON.stringify(error));
|
||||
|
||||
Reference in New Issue
Block a user