@@ -70,6 +70,7 @@ export default function ProfilePage() {
7070 const [ isLinking , setIsLinking ] = useState ( false ) ;
7171 const [ isSyncing , setIsSyncing ] = useState ( false ) ;
7272 const [ discordIdentity , setDiscordIdentity ] = useState < any > ( null ) ;
73+ const [ hasDiscordConnection , setHasDiscordConnection ] = useState ( false ) ;
7374
7475 const handleSendResetEmail = async ( ) => {
7576 if ( ! user ?. email ) return ;
@@ -212,13 +213,17 @@ export default function ProfilePage() {
212213 if ( ! user ) return ;
213214
214215 try {
215- // Get user's linked identities
216+ // Check both auth identities and profile discord_id
216217 const { data : identities , error } = await supabase . auth . getUserIdentities ( ) ;
217218
218219 if ( ! error && identities ) {
219220 const discord = identities . identities ?. find ( ( id : any ) => id . provider === 'discord' ) ;
220221 setDiscordIdentity ( discord ) ;
221222
223+ // Update connection status based on both checks
224+ const isConnected = ! ! ( discord || profile ?. discord_id ) ;
225+ setHasDiscordConnection ( isConnected ) ;
226+
222227 // If user has Discord linked, ensure the Discord ID is saved
223228 if ( discord && discord . provider_id ) {
224229 // First try to call the sync function to ensure Discord ID is saved
@@ -267,14 +272,18 @@ export default function ProfilePage() {
267272 }
268273 }
269274 }
275+ } else {
276+ // Even if no Discord in auth identities, check if profile has discord_id
277+ const isConnected = ! ! profile ?. discord_id ;
278+ setHasDiscordConnection ( isConnected ) ;
270279 }
271280 } catch ( error ) {
272281 console . error ( 'Error fetching Discord identity:' , error ) ;
273282 }
274283 } ;
275284
276285 fetchDiscordIdentity ( ) ;
277- } , [ user ] ) ;
286+ } , [ user , profile ?. discord_id ] ) ;
278287
279288 // Check for #link_discord hash and initiate linking
280289 useEffect ( ( ) => {
@@ -483,8 +492,8 @@ export default function ProfilePage() {
483492 try {
484493 console . log ( 'Starting Discord role sync for user:' , user . id ) ;
485494
486- // Check if user has Discord linked
487- if ( ! profile ?. discord_id ) {
495+ // Check if user has Discord linked (either auth identity or profile discord_id)
496+ if ( ! hasDiscordConnection ) {
488497 toast ( {
489498 title : "Discord Not Connected" ,
490499 description : "Please connect your Discord account first" ,
@@ -934,7 +943,7 @@ export default function ProfilePage() {
934943 < p className = "text-xs text-muted-foreground" > Connect for community features</ p >
935944 </ div >
936945 </ div >
937- { discordIdentity ? (
946+ { hasDiscordConnection ? (
938947 < Badge className = "border border-green-500/30 bg-green-500/10 text-green-600 dark:text-green-400 font-semibold hover:bg-green-500/20 hover:border-green-500/40 transition-colors cursor-default" >
939948 < span className = "flex items-center gap-1" >
940949 < CheckCircle className = "h-3 w-3" />
@@ -951,7 +960,7 @@ export default function ProfilePage() {
951960 ) }
952961 </ div >
953962
954- { ! discordIdentity ? (
963+ { ! hasDiscordConnection ? (
955964 < div className = "space-y-3" >
956965 < p className = "text-sm text-muted-foreground" >
957966 Link your Discord account to sync roles and access exclusive channels in our community server.
0 commit comments