Skip to content

Commit

Permalink
함수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphanoJack committed Jul 25, 2024
1 parent 159a703 commit 68c4413
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
28 changes: 3 additions & 25 deletions lib/screens/mypage/signup/ConfirmationPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:blueberry_flutter_template/providers/SignUpDataProviders.dart';
import 'package:blueberry_flutter_template/providers/user/FirebaseAuthServiceProvider.dart';
import 'package:blueberry_flutter_template/screens/mypage/MyPageScreen.dart';
import 'package:blueberry_flutter_template/services/FirebaseService.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand All @@ -29,6 +30,7 @@ class ConfirmationPage extends ConsumerWidget {
final nickname = ref.read(nicknameProvider.notifier);
final password = ref.read(passwordProvider.notifier);
final isLoading = ref.watch(signUpProvider);
final firebaseService = FirebaseService();

return Padding(
padding: const EdgeInsets.all(16.0),
Expand Down Expand Up @@ -59,7 +61,7 @@ class ConfirmationPage extends ConsumerWidget {
isLoading.when(
data: (value) => ElevatedButton(
onPressed: () async {
await upDateUserDB(email.state, name.state, context, ref);
await firebaseService.upDateUserDB(email.state, name.state);
},
child: const Text('가입하기'),
),
Expand All @@ -71,29 +73,5 @@ class ConfirmationPage extends ConsumerWidget {
);
}

Future<void> upDateUserDB(email, name, BuildContext context, WidgetRef ref) async {
try {
var currentUser = await ref.read(firebaseAuthServiceProvider).getCurrentUser()!;

UserModel newUser = UserModel(
userId: currentUser.uid,
name: name,
email: email,
age: 1,
profileImageUrl: '',
createdAt: DateTime.now());

await ref.read(firebaseStoreServiceProvider).createUser(newUser);

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text(AppStrings.signUpSuccessMessage)),
);
Navigator.push(context, MaterialPageRoute(builder: (context) => MyPageScreen()));
} catch (e) {
print('회원가입 실패: $e');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('회원가입 실패: $e'),
));
}
}
}
25 changes: 25 additions & 0 deletions lib/services/FirebaseService.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:blueberry_flutter_template/model/UserModel.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';

class FirebaseService {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
Expand All @@ -15,4 +17,27 @@ class FirebaseService {
throw Exception('Failed to add message');
}
}
Future<void> upDateUserDB(String email, String name) async {
try {
var user = FirebaseAuth.instance.currentUser;

if (user == null) {
throw Exception('No current user found');
}

UserModel newUser = UserModel(
userId: user.uid,
name: name,
email: email,
age: 1,
profileImageUrl: '',
createdAt: DateTime.now(),
);

await _firestore.collection('users').doc(user.uid).set(newUser.toJson());
} catch (e) {
print('Error updating user: $e');
throw Exception('Failed to update user');
}
}
}
1 change: 0 additions & 1 deletion lib/widgets/signup/EmailVerifyWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class EmailVerifyWidget extends ConsumerWidget {
} catch(e) {
print(e);
}

},
child: Text(AppStrings.click_emailVerification)
)
Expand Down

0 comments on commit 68c4413

Please sign in to comment.