🔧 chore: add handle oauth endpoint login

This commit is contained in:
2026-01-07 23:28:07 +07:00
parent 28cd3178b9
commit 77eeaf1adc
4 changed files with 38 additions and 4 deletions

View File

@ -1,3 +1,4 @@
"use server";
export interface BackendResponse<T = unknown> { export interface BackendResponse<T = unknown> {
success: boolean; success: boolean;
message: string; message: string;

View File

@ -0,0 +1,10 @@
import { cn } from "@/shared/libs/shadcn/lib/utils"
import { Loader2Icon } from "lucide-react"
function Spinner({ className, ...props }: React.ComponentProps<"svg">) {
return (
<Loader2Icon role="status" aria-label="Loading" className={cn("size-4 animate-spin", className)} {...props} />
)
}
export { Spinner }

View File

@ -0,0 +1,6 @@
"use client";
import { backendFetch, BackendResponse } from "@/shared/helper/backendFetch";
export const getOauthEndpoint = async (url: string) => {
return (await backendFetch(url)) as BackendResponse<{ endpointUrl: string }>;
};

View File

@ -16,19 +16,28 @@ import {
GetALlThirdPartyAuthCallback, GetALlThirdPartyAuthCallback,
} from "../actions/getAllThirdPartyAuth"; } from "../actions/getAllThirdPartyAuth";
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
import { Spinner } from "@/shared/libs/shadcn/ui/spinner";
import { getOauthEndpoint } from "../actions/getOauthEndpoint";
import { useRouter } from "next/navigation";
const SignInCard = () => { const SignInCard = () => {
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
const [oAuthProviders, setOAuthProviders] = const [oAuthProviders, setOAuthProviders] =
useState<GetALlThirdPartyAuthCallback | null>(null); useState<GetALlThirdPartyAuthCallback | null>(null);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const res = await getAllThirdPartyAuth(); const res = await getAllThirdPartyAuth();
console.log(res);
setOAuthProviders(res); setOAuthProviders(res);
})(); })();
}, []); }, []);
const getOauthEndpointUrl = async (providerReqEndpoint: string) => {
const res = await getOauthEndpoint(providerReqEndpoint);
router.push(res.data?.endpointUrl || "/");
};
return ( return (
<DialogContent showCloseButton={false}> <DialogContent showCloseButton={false}>
<DialogHeader> <DialogHeader>
@ -56,14 +65,17 @@ const SignInCard = () => {
key={index} key={index}
variant="outline" variant="outline"
className="w-full text-neutral-300 text-xs font-normal" className="w-full text-neutral-300 text-xs font-normal"
disabled={isLoading}
onClick={() => getOauthEndpointUrl(provider.req_endpoint)}
> >
{isLoading && <Spinner />}
<Icon icon={provider.icon} /> <Icon icon={provider.icon} />
Continue with {provider.name} Continue with {provider.name}
</Button> </Button>
))} ))}
</div> </div>
) : ( ) : (
<Button size="sm" className="w-full" isDisabled> <Button size="sm" className="w-full" variant="outline" disabled>
There are no third-party auth providers available. There are no third-party auth providers available.
</Button> </Button>
)} )}
@ -71,9 +83,14 @@ const SignInCard = () => {
</div> </div>
<DialogFooter> <DialogFooter>
<DialogClose asChild> <DialogClose asChild>
<Button variant="outline">Cancel</Button> <Button variant="outline" disabled={isLoading}>
Cancel
</Button>
</DialogClose> </DialogClose>
<Button type="submit">Continue</Button> <Button type="submit" disabled={isLoading}>
{isLoading && <Spinner />}
Continue
</Button>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
); );