- Profile Creation: The database trigger might not be set up in Supabase
- Timing Issue: Frontend used
setTimeoutwhich didn't properly wait - No Profile Fallback: Backend assumed profile existed when creating wallet
- β Now creates profile automatically if it doesn't exist
- β Checks for existing wallet before creating new one
- β Better error messages (409 for duplicates, not 500)
- β
Removed
setTimeout(unreliable) - β Calls wallet initialization immediately after signup
- β
Reuses same
initializeWallet()function for signup and login - β Doesn't block signup if wallet creation fails
User Signs Up
β
Supabase creates auth user
β
Frontend calls /api/auth/init-wallet
β
Backend checks if profile exists
ββ No β Creates profile with user info
ββ Yes β Uses existing profile
β
Backend checks if wallet_id exists
ββ No β Creates Bitnob wallet
ββ Yes β Returns existing wallet
β
Backend saves wallet_id to profile
β
β
User has wallet ready!
- Sign up with a NEW email (fresh user)
- Check browser console - you should see:
β User signed up successfully, initializing wallet... π Initializing wallet... β Wallet initialized: Wallet created successfully - Go to Dashboard - wallet info should display
- Try creating an invoice - should work immediately!
Run this SQL in your Supabase dashboard (optional but recommended):
-- Create automatic profile on user signup
CREATE OR REPLACE FUNCTION handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO public.profiles (id, full_name, email)
VALUES (
NEW.id,
COALESCE(NEW.raw_user_meta_data->>'full_name', SPLIT_PART(NEW.email, '@', 1)),
NEW.email
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE FUNCTION handle_new_user();This makes profile creation even more reliable (happens in database automatically).
The 404s on /api/wallet/info and /api/wallet/balance happen because:
- Wallet doesn't exist yet (first time user)
- The endpoints check for wallet and return 404 if not found
- This is expected behavior until wallet is created
Once wallet is initialized, these 404s will disappear!
Sign up with a brand new email and watch the console - wallet should be created automatically! π