Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MyApp extends StatelessWidget {
class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (Provider.of<firebase.User?>(context) == null) return FormPage();
if (Provider.of<firebase.User?>(context) == null) return ToolReservationPage();
if (Provider.of<firebase.IdTokenResult?>(context) == null) return Loading();
return MyStatefulWidget();
}
Expand Down
30 changes: 25 additions & 5 deletions lib/services/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,41 @@ class Auth {
static bool isInProcess = false;
static firebase.FirebaseAuth _auth = firebase.FirebaseAuth.instance;

static Future signIn(
static Future<void> signUp(
String email, String password, BuildContext context) async {
if (isInProcess) return;
isInProcess = true;
//do login
try {
// Create a new user
await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
// Show a success message
Alert.showAlert(context, "Account created successfully!");
Navigator.pop(context); // Navigate back to the login page
} on firebase.FirebaseAuthException catch (e) {
// Handle authentication errors
Alert.showAlert(context, e.message ?? "Unknown authentication error");
} finally {
isInProcess = false;
}
}

static Future<void> signIn(
String email, String password, BuildContext context) async {
if (isInProcess) return;
isInProcess = true;
try {
// Log in the user
await _auth.signInWithEmailAndPassword(email: email, password: password);
} on firebase.FirebaseAuthException catch (e) {
Alert.showAlert(context, e.message ?? "Unknown authentication error");
}
isInProcess = false;
}

static Future signOut() async {
static Future<void> signOut() async {
await _auth.signOut();
}

Expand All @@ -37,8 +58,7 @@ class Auth {
try {
await _auth.sendPasswordResetEmail(email: email);
} on firebase.FirebaseAuthException catch (e) {
Alert.showAlert(context, e.message ?? "Unknown Authentication error");
print(e);
Alert.showAlert(context, e.message ?? "Unknown authentication error");
}
}

Expand Down
Loading
Loading