Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email Login and Logout #101

Closed
Mohitmadhav opened this issue Oct 2, 2021 · 20 comments · Fixed by #115
Closed

Email Login and Logout #101

Mohitmadhav opened this issue Oct 2, 2021 · 20 comments · Fixed by #115
Assignees
Labels
bug Something isn't working easy Easy level issue firebase For Firebase related issues good first issue good issue for first-time contributors Hacktoberfest For Hacktoberfest 2021 normal-priority Something that has a normal priority

Comments

@Mohitmadhav
Copy link
Member

Description

To implement Email Login in the Initial Screen. Currently, it's resulting in null uid as shown below.

Screenshots

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Initial screen : lib\screens\initial_screen.dart
  2. Auth files: lib\services\auth.dart
  3. Also implement the email log out when the user taps on the logout button.
  4. Private profile: lib\screens\profile\private_profile.dart

Additional data

None

@Mohitmadhav Mohitmadhav added bug Something isn't working easy Easy level issue firebase For Firebase related issues good first issue good issue for first-time contributors Hacktoberfest For Hacktoberfest 2021 normal-priority Something that has a normal priority labels Oct 2, 2021
@keyurgit45
Copy link
Contributor

I can give it a try!

@Mohitmadhav
Copy link
Member Author

Cool @keyurgit45, please can try to implement auth provider if you can.
I'll make the state management easier.

@keyurgit45
Copy link
Contributor

keyurgit45 commented Oct 3, 2021

I can use firebase.instance.authstatechanged . for that we can create a new class to manage these things ?
In main.dart wrapper class route will be given to initialroute. @Mohitmadhav
image

@Mohitmadhav
Copy link
Member Author

I can use firebase.instance.authstatechanged . for that we can create a new class to manage these things ? In main.dart wrapper class route will be given to initialroute. @Mohitmadhav image

Okay @keyurgit45, also make sure to check the expiry time for logging in (Like if a user opens the app after 1 week, then he'll again have to log in). And remove the Wrapper Constructor if you're not using the key somewhere else

@keyurgit45
Copy link
Contributor

keyurgit45 commented Oct 3, 2021

@Mohitmadhav I have made the changes. Log in and log out are working fine. also in the sign-in method, I added the makeUserDataFromAuthUser() method which I forgot to add in prev PR. the issue #106 is due to this. I am really sorry for that. but I haven't implemented that expiry time for logging because I don't know how to implement that. Should I make a PR?

@keyurgit45
Copy link
Contributor

For the expiry time for logging in feature, can we store the time each time when a user opens the app in shared pref and checks if it is been a 1 week or not if yes then it will log out else the user will be on the home screen?

@Mohitmadhav
Copy link
Member Author

For the expiry time for logging in feature, can we store the time each time when a user opens the app in shared pref and checks if it is been a 1 week or not if yes then it will log out else the user will be on the home screen?

In general how long does the user can stay logged in (1 hr) if he doesn't open the app for a few days, which I don't know?

No , don't use shared preferences, I have already setup Flutter Secure Storage Package , have a look at that

@keyurgit45
Copy link
Contributor

official docs : Firebase Authentication sessions are long lived. Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token (a JWT) and refresh token. Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens. Refresh tokens expire only when one of the following occurs:

The user is deleted
The user is disabled
A major account change is detected for the user. This includes events like password or email address updates.

also take a look at my previous comment also.

@Mohitmadhav
Copy link
Member Author

official docs : Firebase Authentication sessions are long lived. Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token (a JWT) and refresh token. Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens. Refresh tokens expire only when one of the following occurs:

The user is deleted The user is disabled A major account change is detected for the user. This includes events like password or email address updates.

also take a look at my previous comment also.

Yeah, I read that too, and also your previous comment.
So don't use shared preference but go for Flutter Secure storage package: https://pub.dev/packages/flutter_secure_storage, and keep the expiry for 2 days instead of a week

See lib\utils\keys_storage.dart

@keyurgit45
Copy link
Contributor

image

I have written this code, when should we call writeCurrentSessionTime() ? @Mohitmadhav
we can write a new timestamp we user open the app but if we want to write when user exits the app , dispose method can't be used. so need to find another way

@Mohitmadhav
Copy link
Member Author

image

I have written this code, when should we call writeCurrentSessionTime() ? @Mohitmadhav we can write a new timestamp we user open the app but if we want to write when user exits the app , dispose method can't be used. so need to find another way

@keyurgit45 it's better to call writeCurrentSesionTime() when the user logs in .
After that, we should call checkForExpiredSession every time the user opens the app again.
If diff>2, then the user will be logged out.
Then the user will have to sign in again, after which, the writeCurrentSessionTime() will be called again to store the current login time.

@keyurgit45
Copy link
Contributor

keyurgit45 commented Oct 3, 2021

means you want, the user should sign-in in every 2 days? @Mohitmadhav

@Mohitmadhav
Copy link
Member Author

means you want, the user should sign-in in every 2 days? @Mohitmadhav

Actually, if the user does not open the app for more than 2 days, then he should sign in again.

@keyurgit45
Copy link
Contributor

means you want, the user should sign-in in every 2 days? @Mohitmadhav

Actually, if the user does not open the app for more than 2 days, then he should sign in again.

ok got it

@Mohitmadhav
Copy link
Member Author

Mohitmadhav commented Oct 4, 2021

@Mohitmadhav I have made the changes. Log in and log out are working fine. also in the sign-in method, I added the makeUserDataFromAuthUser() method which I forgot to add in prev PR. the issue #106 is due to this. I am really sorry for that. but I haven't implemented that expiry time for logging because I don't know how to implement that. Should I make a PR?

I can assign #106 to you and then you can create another PR for those missing changes.

@keyurgit45
Copy link
Contributor

@Mohitmadhav Okay...firstly I will make PR for login and logout and then for issue #106

@keyurgit45
Copy link
Contributor

image

after doing git pull upstream main, I am getting this. I need onAuthStateChanged method, what to do here? @Mohitmadhav

@Mohitmadhav
Copy link
Member Author

can you show the complete screenshot once?

@keyurgit45
Copy link
Contributor

image

@Mohitmadhav
Copy link
Member Author

Ok cool, accept the incoming changes then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy Easy level issue firebase For Firebase related issues good first issue good issue for first-time contributors Hacktoberfest For Hacktoberfest 2021 normal-priority Something that has a normal priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants