✨ feat: add oauth button
This commit is contained in:
14
shared/widgets/signin/actions/getAllThirdPartyAuth.ts
Normal file
14
shared/widgets/signin/actions/getAllThirdPartyAuth.ts
Normal file
@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
import { backendFetch, BackendResponse } from "@/shared/helper/backendFetch";
|
||||
|
||||
export type GetALlThirdPartyAuthCallback = BackendResponse<
|
||||
{
|
||||
name: string;
|
||||
icon: string;
|
||||
req_endpoint: string;
|
||||
}[]
|
||||
>;
|
||||
|
||||
export const getAllThirdPartyAuth = async () => {
|
||||
return (await backendFetch("auth/providers")) as GetALlThirdPartyAuthCallback;
|
||||
};
|
||||
@ -10,8 +10,25 @@ import {
|
||||
import { Input } from "@/shared/libs/shadcn/ui/input";
|
||||
import { Label } from "@/shared/libs/shadcn/ui/label";
|
||||
import { Separator } from "@/shared/libs/shadcn/ui/separator";
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
getAllThirdPartyAuth,
|
||||
GetALlThirdPartyAuthCallback,
|
||||
} from "../actions/getAllThirdPartyAuth";
|
||||
import { Icon } from "@iconify/react";
|
||||
|
||||
const SignInCard = () => {
|
||||
const [oAuthProviders, setOAuthProviders] =
|
||||
useState<GetALlThirdPartyAuthCallback | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const res = await getAllThirdPartyAuth();
|
||||
console.log(res);
|
||||
setOAuthProviders(res);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<DialogContent showCloseButton={false}>
|
||||
<DialogHeader>
|
||||
@ -26,6 +43,31 @@ const SignInCard = () => {
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input type="email" id="email" placeholder="e.g. user@example.com" />
|
||||
</div>
|
||||
<div className="my-4 flex items-center gap-2 ">
|
||||
<Separator className="flex-1 bg-neutral-700" />
|
||||
<p className="text-neutral-500 text-sm">or continue with</p>
|
||||
<Separator className="flex-1 bg-neutral-700" />
|
||||
</div>
|
||||
<div>
|
||||
{oAuthProviders ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
{oAuthProviders.data?.map((provider, index) => (
|
||||
<Button
|
||||
key={index}
|
||||
variant="outline"
|
||||
className="w-full text-neutral-300 text-xs font-normal"
|
||||
>
|
||||
<Icon icon={provider.icon} />
|
||||
Continue with {provider.name}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Button size="sm" className="w-full" isDisabled>
|
||||
There are no third-party auth providers available.
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
|
||||
Reference in New Issue
Block a user