-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Smalick0478/v2
🎉 Pull Request: Flutter Migration & Feature Enhancements 🚀
- Loading branch information
Showing
8 changed files
with
392 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ | |
|
||
import 'package:flutter/material.dart'; | ||
import 'package:rafay_portfolio/frontend/admin/pages/auth/opt.dart'; | ||
import 'package:rafay_portfolio/frontend/admin/pages/auth/otp_email.dart'; | ||
import 'package:rafay_portfolio/frontend/admin/pages/dashboardPage.dart'; | ||
import 'package:rafay_portfolio/constants/widgets/dialogBox/dialogbox.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:email_otp/email_otp.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AuthService { | ||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
|
||
EmailOTP myauth = EmailOTP(); | ||
Future<UserCredential?> signInWithEmailAndPassword( | ||
BuildContext context, String email, String password) async { | ||
try { | ||
|
@@ -38,50 +41,76 @@ class AuthService { | |
|
||
// If the user is authenticated, start the phone number verification process | ||
if (userCredential != null && userCredential.user != null) { | ||
await FirebaseAuth.instance.verifyPhoneNumber( | ||
phoneNumber: phoneNumber, | ||
verificationCompleted: (PhoneAuthCredential credential) async { | ||
await FirebaseAuth.instance.signInWithCredential(credential); | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const DashboardPage(), | ||
), | ||
); | ||
}, | ||
verificationFailed: (FirebaseAuthException e) { | ||
showDialogBox( | ||
context, | ||
Icons.error, | ||
Colors.red, | ||
Colors.red, | ||
'Error', | ||
e.message ?? 'An error occurred.', | ||
() => Navigator.of(context).pop(), | ||
); | ||
}, | ||
codeSent: (String verificationId, int? resendToken) { | ||
Navigator.push( | ||
// await FirebaseAuth.instance.verifyPhoneNumber( | ||
// phoneNumber: phoneNumber, | ||
// verificationCompleted: (PhoneAuthCredential credential) async { | ||
// await FirebaseAuth.instance.signInWithCredential(credential); | ||
// Navigator.push( | ||
// context, | ||
// MaterialPageRoute( | ||
// builder: (context) => const DashboardPage(), | ||
// ), | ||
// ); | ||
// }, | ||
// verificationFailed: (FirebaseAuthException e) { | ||
// showDialogBox( | ||
// context, | ||
// Icons.error, | ||
// Colors.red, | ||
// Colors.red, | ||
// 'Error', | ||
// e.message ?? 'An error occurred.', | ||
// () => Navigator.of(context).pop(), | ||
// ); | ||
// }, | ||
// codeSent: (String verificationId, int? resendToken) { | ||
// Navigator.push( | ||
// context, | ||
// MaterialPageRoute( | ||
// builder: (context) => OtpPage( | ||
// verificationId: verificationId, | ||
// ), | ||
// ), | ||
// ); | ||
// }, | ||
// codeAutoRetrievalTimeout: (String verificationId) { | ||
// showDialogBox( | ||
// context, | ||
// Icons.error, | ||
// Colors.red, | ||
// Colors.red, | ||
// 'Error', | ||
// 'Sorry OTP Expired', | ||
// () => Navigator.of(context).pop(), | ||
// ); | ||
// }, | ||
// ); | ||
|
||
myauth.setConfig( | ||
appEmail: "[email protected]", | ||
appName: "Admin", | ||
userEmail: email, | ||
otpLength: 4, | ||
otpType: OTPType.digitsOnly); | ||
|
||
var template = | ||
'Hi {{app_name}} Your OTP Code For Admin Dashboard is {{otp}}.'; | ||
myauth.setTemplate(render: template); | ||
if (await myauth.sendOTP() == true) { | ||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( | ||
content: Text("OTP has been sent"), | ||
)); | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => OtpPage( | ||
verificationId: verificationId, | ||
), | ||
), | ||
); | ||
}, | ||
codeAutoRetrievalTimeout: (String verificationId) { | ||
showDialogBox( | ||
context, | ||
Icons.error, | ||
Colors.red, | ||
Colors.red, | ||
'Error', | ||
'Sorry OTP Expired', | ||
() => Navigator.of(context).pop(), | ||
); | ||
}, | ||
); | ||
builder: (context) => OtpEmailVerifyScreen( | ||
myauth: myauth, | ||
))); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( | ||
content: Text("Oops, OTP send failed"), | ||
)); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.