Skip to content

Commit

Permalink
a proper registration method implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
SMSourov committed Sep 25, 2023
1 parent 3514cbb commit 1faae39
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:cleanifi/constants/routes.dart';
import 'package:cleanifi/firebase_options.dart';
import 'package:cleanifi/views/login_view.dart';
import 'package:cleanifi/views/register_view.dart';
import 'package:cleanifi/views/verify_email.dart';
import 'package:cleanifi/views/verify_email_view.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/views/register_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class _RegisterViewState extends State<RegisterView> {
email: email,
password: password,
);
final user = FirebaseAuth.instance.currentUser;
await user?.sendEmailVerification();
Navigator.of(context).pushNamed(verifyEmailRoute);
} on FirebaseAuthException catch (e) {
if (e.code == "email-already-in-use") {
Expand Down
31 changes: 0 additions & 31 deletions lib/views/verify_email.dart

This file was deleted.

46 changes: 46 additions & 0 deletions lib/views/verify_email_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:cleanifi/constants/routes.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

class VerifyEmailView extends StatefulWidget {
const VerifyEmailView({super.key});

@override
State<VerifyEmailView> createState() => _VerifyEmailViewState();
}

class _VerifyEmailViewState extends State<VerifyEmailView> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Verify your email"),
),
body: Column(
children: [
const Text(
"We've send a verifiction email to email address. Please check your email and verify your account"),
const Text(
"Not received any email yet, press the button below to send the email again"),
TextButton(
onPressed: () async {
final user = FirebaseAuth.instance.currentUser;
await user?.sendEmailVerification();
},
child: const Text("Send email verification"),
),
TextButton(
onPressed: () async {
await FirebaseAuth.instance.signOut();
Navigator.of(context).pushNamedAndRemoveUntil(
registerRoute,
(route) => false,
);
},
child: const Text("Restart"),
),
],
),
);
}
}

0 comments on commit 1faae39

Please sign in to comment.