diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 654433da..c81eef5b 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -24,18 +24,16 @@ export default async function SignInPage() { - + - {SUPPORTED_PROVIDERS.filter((p) => !p.isManual).length > 0 && ( + {SUPPORTED_PROVIDERS.filter((p) => !p.isManual && p.isActive).length > 0 && ( <> -
OR
- - + )} @@ -50,7 +48,5 @@ export default async function SignInPage() { - - ) } diff --git a/portabase.config.ts b/portabase.config.ts index b8bc3fcc..a7ce6ea8 100644 --- a/portabase.config.ts +++ b/portabase.config.ts @@ -1,9 +1,9 @@ -import {Chrome, KeyRound, LucideIcon} from "lucide-react"; export interface AuthProviderConfig { id: "google" | "github" | "credential"; - icon: LucideIcon; + isActive: boolean; + icon: string; isManual?: boolean; credentials?: { clientId: string; @@ -80,7 +80,8 @@ export const PORTABASE_DEFAULT_SETTINGS = { export const SUPPORTED_PROVIDERS: AuthProviderConfig[] = [ { id: "google", - icon: Chrome, + icon: "hugeicons:chrome", + isActive: Boolean(process.env.AUTH_GOOGLE_METHOD), // isManual: true, credentials: { clientId: process.env.GOOGLE_CLIENT_ID || "", @@ -100,7 +101,8 @@ export const SUPPORTED_PROVIDERS: AuthProviderConfig[] = [ },*/ { id: "credential", - icon: KeyRound, + isActive: true, + icon: "proicons:key", isManual: true, credentials: { clientId: "", diff --git a/src/components/wrappers/auth/social-buttons.tsx b/src/components/wrappers/auth/social-buttons.tsx index b3c69fa1..a4fb9638 100644 --- a/src/components/wrappers/auth/social-buttons.tsx +++ b/src/components/wrappers/auth/social-buttons.tsx @@ -5,9 +5,12 @@ import { Button } from "@/components/ui/button"; import { authClient } from "@/lib/auth/auth-client"; import { Loader2 } from "lucide-react"; import { toast } from "sonner"; -import {SUPPORTED_PROVIDERS} from "../../../../portabase.config"; +import {AuthProviderConfig} from "../../../../portabase.config"; +import {Icon} from "@iconify/react"; + +export function SocialAuthButtons({ providers }: { providers: AuthProviderConfig[] }) { + const socialProviders = providers.filter(p => p.isActive && !p.isManual); -export function SocialAuthButtons() { const [isLoading, setIsLoading] = useState(null); const handleSocialSignIn = async (providerId: string) => { @@ -30,16 +33,15 @@ export function SocialAuthButtons() { } }; - const socialProviders = SUPPORTED_PROVIDERS.filter((p) => !p.isManual); - if (socialProviders.length === 0) return null; - return (
{socialProviders.map((provider) => ( ))} diff --git a/src/components/wrappers/dashboard/common/logged-in/logged-in-button.server.tsx b/src/components/wrappers/dashboard/common/logged-in/logged-in-button.server.tsx index fa79865f..61e75474 100644 --- a/src/components/wrappers/dashboard/common/logged-in/logged-in-button.server.tsx +++ b/src/components/wrappers/dashboard/common/logged-in/logged-in-button.server.tsx @@ -1,6 +1,7 @@ import {currentUser} from "@/lib/auth/current-user"; import {getAccounts, getSession, getSessions} from "@/lib/auth/auth"; import {LoggedInButtonClient} from "./logged-in-button"; +import {SUPPORTED_PROVIDERS} from "../../../../../../portabase.config"; export const LoggedInButton = async () => { const user = await currentUser(); @@ -18,6 +19,7 @@ export const LoggedInButton = async () => { // @ts-ignore currentSession={currentSession.session} accounts={accounts} + providers={SUPPORTED_PROVIDERS.filter((p) => p.isActive)} /> ); }; diff --git a/src/components/wrappers/dashboard/common/logged-in/logged-in-button.tsx b/src/components/wrappers/dashboard/common/logged-in/logged-in-button.tsx index 42ee70df..afe14e62 100644 --- a/src/components/wrappers/dashboard/common/logged-in/logged-in-button.tsx +++ b/src/components/wrappers/dashboard/common/logged-in/logged-in-button.tsx @@ -1,46 +1,3 @@ -// import { ChevronUp } from "lucide-react"; -// -// import {Avatar, AvatarFallback, AvatarImage} from "@/components/ui/avatar"; -// import { currentUser } from "@/lib/auth/current-user"; -// import { SidebarMenuButton } from "@/components/ui/sidebar"; -// import { getAccounts, getSession, getSessions } from "@/lib/auth/auth"; -// import {LoggedInDropdown} from "@/components/wrappers/dashboard/common/logged-in/logged-in-dropdown"; -// -// export const LoggedInButton = async () => { -// const user = await currentUser(); -// const sessions = await getSessions(); -// const currentSession = await getSession(); -// const accounts = await getAccounts(); -// -// if (!user) return null; -// -// -// return ( -// <> -// -// -// -// -// {user?.name[0].toUpperCase()} -// {user?.image ? : null} -// -// -// {user?.name} -// -// -// -// -// ); -// }; "use client"; import {ChevronUp} from "lucide-react"; @@ -48,15 +5,23 @@ import {Avatar, AvatarFallback, AvatarImage} from "@/components/ui/avatar"; import {SidebarMenuButton} from "@/components/ui/sidebar"; import {LoggedInDropdown} from "./logged-in-dropdown"; import {Account, Session, User} from "better-auth"; +import {AuthProviderConfig} from "../../../../../../portabase.config"; type LoggedInButtonClientProps = { - user: User; - sessions: Session[]; - currentSession: Session; - accounts: Account[]; + user: User, + sessions: Session[], + currentSession: Session, + accounts: Account[], + providers: AuthProviderConfig[] } -export const LoggedInButtonClient = ({user, sessions, currentSession, accounts}: LoggedInButtonClientProps) => { +export const LoggedInButtonClient = ({ + user, + sessions, + currentSession, + accounts, + providers + }: LoggedInButtonClientProps) => { return ( diff --git a/src/components/wrappers/dashboard/common/logged-in/logged-in-dropdown.tsx b/src/components/wrappers/dashboard/common/logged-in/logged-in-dropdown.tsx index 7fd0afa3..386fe156 100644 --- a/src/components/wrappers/dashboard/common/logged-in/logged-in-dropdown.tsx +++ b/src/components/wrappers/dashboard/common/logged-in/logged-in-dropdown.tsx @@ -7,6 +7,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigge import { signOut } from "@/lib/auth/auth-client"; import {ProfileModal} from "@/components/wrappers/dashboard/common/profile/profile-modal"; import {Account, Session, User} from "@/db/schema/02_user"; +import {AuthProviderConfig} from "../../../../../../portabase.config"; export type LoggedInDropdownProps = PropsWithChildren<{ user: User; @@ -14,9 +15,11 @@ export type LoggedInDropdownProps = PropsWithChildren<{ currentSession: Session; accounts: Account[]; children: ReactNode; + providers: AuthProviderConfig[] + }>; -export const LoggedInDropdown = ({ user, sessions, currentSession, accounts, children }: LoggedInDropdownProps) => { +export const LoggedInDropdown = ({ user, sessions, currentSession, accounts, children, providers }: LoggedInDropdownProps) => { const router = useRouter(); const [isModalOpen, setIsModalOpen] = useState(false); @@ -29,6 +32,7 @@ export const LoggedInDropdown = ({ user, sessions, currentSession, accounts, chi accounts={accounts} open={isModalOpen} onOpenChange={setIsModalOpen} + providers={providers} /> diff --git a/src/components/wrappers/dashboard/common/profile/profile-modal.tsx b/src/components/wrappers/dashboard/common/profile/profile-modal.tsx index b38a77a7..9fa99913 100644 --- a/src/components/wrappers/dashboard/common/profile/profile-modal.tsx +++ b/src/components/wrappers/dashboard/common/profile/profile-modal.tsx @@ -10,6 +10,7 @@ import {ProfileAccount} from "@/components/wrappers/dashboard/profile/profile-ac import {ProfileAppearance} from "@/components/wrappers/dashboard/profile/profile-apperance"; import {ProfileSecurity} from "@/components/wrappers/dashboard/profile/profile-security"; import {ProfileGeneral} from "@/components/wrappers/dashboard/profile/profile-general"; +import {AuthProviderConfig} from "../../../../../../portabase.config"; type ProfileModalProps = { open: boolean; @@ -18,9 +19,11 @@ type ProfileModalProps = { currentSession: Session; accounts: Account[]; onOpenChange: (open: boolean) => void; + providers: AuthProviderConfig[] + }; -export const ProfileModal = ({ user, sessions, currentSession, accounts, open, onOpenChange }: ProfileModalProps) => { +export const ProfileModal = ({ user, sessions, currentSession, accounts, open, onOpenChange, providers }: ProfileModalProps) => { return ( @@ -46,7 +49,7 @@ export const ProfileModal = ({ user, sessions, currentSession, accounts, open, o - + diff --git a/src/components/wrappers/dashboard/profile/profile-providers.tsx b/src/components/wrappers/dashboard/profile/profile-providers.tsx index 78131aa2..e6167487 100644 --- a/src/components/wrappers/dashboard/profile/profile-providers.tsx +++ b/src/components/wrappers/dashboard/profile/profile-providers.tsx @@ -12,13 +12,16 @@ import {useRouter} from "next/navigation"; import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip"; import {Alert, AlertDescription} from "@/components/ui/alert"; import {SetPasswordProfileProviderModal} from "./modal/set-password-modal"; -import {SUPPORTED_PROVIDERS} from "../../../../../portabase.config"; +import {AuthProviderConfig} from "../../../../../portabase.config"; +import {Icon} from "@iconify/react"; interface ProfileProviderProps { accounts: Account[]; + providers: AuthProviderConfig[] + } -export function ProfileProviders({accounts}: ProfileProviderProps) { +export function ProfileProviders({accounts, providers}: ProfileProviderProps) { const router = useRouter(); const totalConnected = accounts.length; const [loadingProvider, setLoadingProvider] = useState(null); @@ -70,7 +73,7 @@ export function ProfileProviders({accounts}: ProfileProviderProps) {
- {SUPPORTED_PROVIDERS.map((provider) => { + {providers.map((provider) => { const linkedAccount = accounts.find((acc) => acc.providerId === provider.id); const isConnected = !!linkedAccount; // const canUnlink = totalConnected > 1 || (totalConnected === 1 && !provider.isManual); @@ -83,7 +86,7 @@ export function ProfileProviders({accounts}: ProfileProviderProps) { className="flex items-center justify-between p-4 border rounded-lg hover:bg-muted/30 transition-colors">
- +
diff --git a/src/lib/auth/auth.ts b/src/lib/auth/auth.ts index eddee909..67855e3a 100644 --- a/src/lib/auth/auth.ts +++ b/src/lib/auth/auth.ts @@ -11,7 +11,7 @@ import {count, eq} from "drizzle-orm"; import {MemberWithUser, OrganizationWithMembersAndUsers} from "@/db/schema/03_organization"; import {sendEmail} from "@/lib/email/email-helper"; import {render} from "@react-email/render"; -import {SUPPORTED_PROVIDERS} from "../../../portabase.config"; +import {AuthProviderConfig, SUPPORTED_PROVIDERS} from "../../../portabase.config"; import {withUpdatedAt} from "@/db/utils"; import EmailVerification from "@/components/emails/auth/email-verification"; import EmailForgotPassword from "@/components/emails/auth/email-forgot-password"; @@ -80,6 +80,7 @@ export const auth = betterAuth({ }, }, socialProviders: SUPPORTED_PROVIDERS.reduce((acc: any, provider: any) => { + if (!provider.isActive) return acc; if (provider.id === "credential") return acc; if (provider.id === "google") { acc.google = {