👔 add provider option
Create a provider option in the callback handler to define the provider name for flexibility when used with multiple providers and requiring multiple endpoints.
This commit is contained in:
@ -1,9 +1,9 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { api } from "@/shared/api/connector";
|
import { api } from "@/shared/api/connector";
|
||||||
|
|
||||||
export const SendCallbackToServer = async (data: string) => {
|
export const SendCallbackToServer = async (data: string, provider: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`auth/google/callback${data}`);
|
const response = await api.get(`auth/${provider}/callback${data}`);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -3,8 +3,10 @@
|
|||||||
import { CircularProgress } from "@heroui/react";
|
import { CircularProgress } from "@heroui/react";
|
||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
import { SendCallbackToServer } from "../lib/sendCallbackToServer";
|
import { SendCallbackToServer } from "../lib/sendCallbackToServer";
|
||||||
|
import { useParams } from "next/navigation";
|
||||||
|
|
||||||
const LoadingProcess = () => {
|
const LoadingProcess = () => {
|
||||||
|
const params = useParams();
|
||||||
const calledRef = useRef(false);
|
const calledRef = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (calledRef.current) return;
|
if (calledRef.current) return;
|
||||||
@ -12,7 +14,10 @@ const LoadingProcess = () => {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await SendCallbackToServer(window.location.search);
|
await SendCallbackToServer(
|
||||||
|
window.location.search,
|
||||||
|
params.provider as string
|
||||||
|
);
|
||||||
window.close();
|
window.close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user