🎨 format oauth provider list
fixing the list format on oauth login.
This commit is contained in:
@ -1,9 +0,0 @@
|
|||||||
"use server";
|
|
||||||
import { api } from "@/shared/api/connector";
|
|
||||||
|
|
||||||
const getGoogleAuthUrl = async () => {
|
|
||||||
const res = await api.get(`debug`);
|
|
||||||
return res.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getGoogleAuthUrl;
|
|
||||||
9
features/auth/lib/getOauthProviderList.ts
Normal file
9
features/auth/lib/getOauthProviderList.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"use server";
|
||||||
|
import { api } from "@/shared/api/connector";
|
||||||
|
|
||||||
|
const getOauthProviderList = async () => {
|
||||||
|
const res = await api.get(`auth/providers`);
|
||||||
|
return res.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getOauthProviderList;
|
||||||
8
features/auth/types/oauthProvidersList.ts
Normal file
8
features/auth/types/oauthProvidersList.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
interface oauthProviders {
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
req_endpoint: string;
|
||||||
|
client_id: string | undefined;
|
||||||
|
client_secret: string | undefined;
|
||||||
|
client_callback: string;
|
||||||
|
}
|
||||||
@ -3,40 +3,28 @@
|
|||||||
import { Button } from "@heroui/react";
|
import { Button } from "@heroui/react";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import getGoogleAuthUrl from "../lib/getGoogleAuthUrl";
|
import getOauthProviderList from "../lib/getOauthProviderList";
|
||||||
|
|
||||||
const OAuthProviders = () => {
|
const OAuthProviders = () => {
|
||||||
const [UrlOauth, setUrlOauth] = useState("please wait...");
|
const [oauthProvidersList, setOauthProvidersList] = useState<
|
||||||
|
oauthProviders[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getGoogleAuthUrl(); // panggil server function
|
const res = (await getOauthProviderList()) as oauthProviders[];
|
||||||
setUrlOauth(JSON.stringify(res));
|
setOauthProvidersList(res);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// set to true if there are other providers coming soon
|
|
||||||
const comingSoonProviders: boolean = true;
|
|
||||||
|
|
||||||
// Provider for third-party auth
|
|
||||||
const oAuthProviders = [
|
|
||||||
{
|
|
||||||
name: "Google",
|
|
||||||
icon: "logos:google-icon",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Discord",
|
|
||||||
icon: "logos:discord-icon",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full flex flex-col gap-2 mt-4">
|
<div className="w-full flex flex-col gap-2 mt-4">
|
||||||
{oAuthProviders.map((provider, index) => {
|
{oauthProvidersList.length > 0 ? (
|
||||||
|
oauthProvidersList.map((provider, index) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
key={index}
|
key={index}
|
||||||
@ -47,13 +35,10 @@ const OAuthProviders = () => {
|
|||||||
Continue with {provider.name}
|
Continue with {provider.name}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
|
) : (
|
||||||
<h1>{UrlOauth}</h1>
|
|
||||||
|
|
||||||
{comingSoonProviders && (
|
|
||||||
<Button className="w-full" variant="ghost" isDisabled>
|
<Button className="w-full" variant="ghost" isDisabled>
|
||||||
Other login options will come soon
|
No login options available via third-party providers
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user