Skip to content

Commit

Permalink
Update page.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ArhanAnsari authored Oct 26, 2024
1 parent b68c3d1 commit d454587
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"use client";

import { useState, useEffect } from "react";
import { getAuth, signOut, updateProfile, User, linkWithPopup, GoogleAuthProvider, GithubAuthProvider, fetchSignInMethodsForEmail } from "firebase/auth";
import { getUserData, updateUserData } from "@/firebaseFunctions";
import { getAuth, signOut, updateProfile, User, linkWithPopup, GoogleAuthProvider, GithubAuthProvider } from "firebase/auth";
import { getUserData, updateUserData, connectProvider, getConnectedProviders } from "@/firebaseFunctions";
import { useSession, signIn } from "next-auth/react";

interface UserData {
Expand Down Expand Up @@ -34,8 +34,8 @@ const ProfilePage = () => {
const data = await getUserData(currentUser.email!);
setUserData(data as UserData);

// Fetch connected providers
const providers = await fetchSignInMethodsForEmail(auth, currentUser.email!);
// Fetch connected providers from Firestore
const providers = await getConnectedProviders(currentUser.email!);
setConnectedProviders(providers);
} catch (error) {
console.error("Error fetching profile data:", error);
Expand Down Expand Up @@ -81,6 +81,7 @@ const ProfilePage = () => {

try {
await linkWithPopup(user, providerInstance);
await connectProvider(user.email!, provider);
alert(`${provider.charAt(0).toUpperCase() + provider.slice(1)} has been successfully linked to your account.`);
setConnectedProviders((prev) => [...prev, provider]);
} catch (error: any) {
Expand Down Expand Up @@ -146,15 +147,15 @@ const ProfilePage = () => {
<h3>Connect Providers:</h3>
<button
onClick={() => handleProviderLink("google")}
disabled={connectedProviders.includes("google.com")}
disabled={connectedProviders.includes("google")}
>
{connectedProviders.includes("google.com") ? "Google (Connected)" : "Connect Google"}
{connectedProviders.includes("google") ? "Google (Connected)" : "Connect Google"}
</button>
<button
onClick={() => handleProviderLink("github")}
disabled={connectedProviders.includes("github.com")}
disabled={connectedProviders.includes("github")}
>
{connectedProviders.includes("github.com") ? "GitHub (Connected)" : "Connect GitHub"}
{connectedProviders.includes("github") ? "GitHub (Connected)" : "Connect GitHub"}
</button>
</div>
</div>
Expand Down

0 comments on commit d454587

Please sign in to comment.