@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
22import { createPortal } from 'react-dom'
33import { supabase } from '@/lib/supabase/client'
44import { useRouter } from 'next/navigation'
5+ import { toast } from 'react-hot-toast'
56
67interface ProfileModalProps {
78 open : boolean
@@ -25,6 +26,7 @@ export default function ProfileModal({ open, onClose }: ProfileModalProps) {
2526 setError ( null )
2627 const { data : { user } , error : userError } = await supabase . auth . getUser ( )
2728 if ( userError || ! user ) {
29+ toast . error ( userError ?. message || 'Auth error. Please sign in again.' )
2830 router . replace ( '/sign-in' )
2931 return
3032 }
@@ -34,7 +36,10 @@ export default function ProfileModal({ open, onClose }: ProfileModalProps) {
3436 . eq ( 'id' , user . id )
3537 . single ( )
3638 if ( ! ignore ) {
37- if ( profileError ) setError ( profileError . message )
39+ if ( profileError ) {
40+ setError ( profileError . message )
41+ toast . error ( profileError . message )
42+ }
3843 else {
3944 setProfile ( {
4045 email : data ?. email || '' ,
@@ -58,14 +63,25 @@ export default function ProfileModal({ open, onClose }: ProfileModalProps) {
5863 . from ( 'users' )
5964 . update ( { full_name : fullName } )
6065 . eq ( 'id' , user ?. id || '' )
61- if ( updateError ) setError ( updateError . message )
66+ if ( updateError ) {
67+ setError ( updateError . message )
68+ toast . error ( updateError . message )
69+ }
6270 else setSuccess ( 'Profile updated!' )
6371 setLoading ( false )
6472 }
6573
6674 const handleLogout = async ( ) => {
67- await supabase . auth . signOut ( )
68- router . replace ( '/sign-in' )
75+ try {
76+ await supabase . auth . signOut ( )
77+ router . replace ( '/sign-in' )
78+ } catch ( err : unknown ) {
79+ if ( err && typeof err === 'object' && 'message' in err && typeof ( err as { message ?: unknown } ) . message === 'string' ) {
80+ toast . error ( ( err as { message : string } ) . message )
81+ } else {
82+ toast . error ( 'Logout failed' )
83+ }
84+ }
6985 }
7086
7187 const handleDelete = async ( ) => {
@@ -75,7 +91,10 @@ export default function ProfileModal({ open, onClose }: ProfileModalProps) {
7591 const { data : { user } } = await supabase . auth . getUser ( )
7692 // You should use a secure API route for this in production
7793 const { error : deleteError } = await supabase . from ( 'users' ) . delete ( ) . eq ( 'id' , user ?. id || '' )
78- if ( deleteError ) setError ( deleteError . message )
94+ if ( deleteError ) {
95+ setError ( deleteError . message )
96+ toast . error ( deleteError . message )
97+ }
7998 else {
8099 await supabase . auth . signOut ( )
81100 router . replace ( '/sign-up' )
0 commit comments