🔧 chore: add handle oauth endpoint login
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
"use server";
|
||||||
export interface BackendResponse<T = unknown> {
|
export interface BackendResponse<T = unknown> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
|
|||||||
10
shared/libs/shadcn/ui/spinner.tsx
Normal file
10
shared/libs/shadcn/ui/spinner.tsx
Normal 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 }
|
||||||
6
shared/widgets/signin/actions/getOauthEndpoint.ts
Normal file
6
shared/widgets/signin/actions/getOauthEndpoint.ts
Normal 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 }>;
|
||||||
|
};
|
||||||
@ -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>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user