fix: Handle family data correctly during registration and onboarding
- Extract family data from registration response and add to user object - Backend returns family separately in registration, but included in user for login - Remove error messages for language/measurement preferences (they save correctly) - Add detailed console logging for debugging family issues - Improve error message when family is missing during child creation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -170,7 +170,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
// Backend returns { success, data: { user, family, tokens } }
|
||||
const { data: responseData } = response.data;
|
||||
const { tokens, user: userData } = responseData;
|
||||
const { tokens, user: userData, family: familyData } = responseData;
|
||||
|
||||
if (!tokens?.accessToken || !tokens?.refreshToken) {
|
||||
throw new Error('Invalid response from server');
|
||||
@@ -178,9 +178,19 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const { accessToken, refreshToken } = tokens;
|
||||
|
||||
// Add family data to user object (registration returns family separately)
|
||||
const userWithFamily = {
|
||||
...userData,
|
||||
families: familyData ? [{
|
||||
id: familyData.id,
|
||||
familyId: familyData.id,
|
||||
role: familyData.role || 'parent',
|
||||
}] : [],
|
||||
};
|
||||
|
||||
tokenStorage.setTokens(accessToken, refreshToken);
|
||||
setToken(accessToken);
|
||||
setUser(userData);
|
||||
setUser(userWithFamily);
|
||||
|
||||
// Redirect to onboarding
|
||||
router.push('/onboarding');
|
||||
|
||||
Reference in New Issue
Block a user