Skip to content

Commit

Permalink
JWT expiration error
Browse files Browse the repository at this point in the history
  • Loading branch information
Thesmader committed Apr 25, 2020
1 parent b5cdc73 commit df01545
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions gogrocy/lib/core/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Apis {
"state": "Odisha",
"country": "India",
};
print(body);
http.Response result = await http.post(addAddress,
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"}, body: body);
print(result.body);
Expand Down Expand Up @@ -171,8 +172,9 @@ class Apis {
Future<bool> verifyUserApi(String jwt) async {
http.Response result = await http.post(verifyUser,
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"});
if ((json.decode(result.body))["success"])
return true;
if ((json.decode(result.body))["success"]){
print("VERIFIED USER");
return true;}
else
return false;
}
Expand Down
20 changes: 14 additions & 6 deletions gogrocy/lib/core/services/authentication_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:gogrocy/core/services/navigation_service.dart';
import 'package:gogrocy/core/services/shared_prefs.dart';
import 'package:gogrocy/service_locator.dart';

Expand All @@ -8,12 +9,18 @@ class AuthenticationService {
String verificationId;

final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
final NavigationService _navigationService = locator<NavigationService>();

Future verifyPhoneNumber(BuildContext context, String phoneNumber) async {
Future verifyPhoneNumber(BuildContext context, String phoneNumber, String countryCode) async {
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential credential) {
(AuthCredential credential) async {
print('Verification Complete');
signInWithNumber(context, credential);
await signInWithNumber(context, credential);
print("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
_navigationService.navigateTo('awesome', arguments:{
"phoneNumber": phoneNumber,
"countryCode": countryCode
});
};

final PhoneVerificationFailed verificationFailed =
Expand All @@ -34,8 +41,8 @@ class AuthenticationService {

try {
await firebaseInstance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 60),
phoneNumber: countryCode + " " + phoneNumber,
timeout: Duration(seconds: 10),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: phoneCodeSent,
Expand All @@ -49,7 +56,7 @@ class AuthenticationService {
}
}

signInWithNumber(BuildContext context, AuthCredential credential) async {
Future signInWithNumber(BuildContext context, AuthCredential credential) async {
try {
FirebaseUser user =
(await firebaseInstance.signInWithCredential(credential)).user;
Expand All @@ -75,6 +82,7 @@ class AuthenticationService {

Future<bool> isUserLoggedIn() async {
var loggedIn = await _sharedPrefsService.hasUser();
print(loggedIn);
if(loggedIn){
return true;
}else{
Expand Down
4 changes: 2 additions & 2 deletions gogrocy/lib/core/viewModels/login_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LoginModel extends BaseModel {
var finalNumber = countryCode + " " + phoneNumber;

var result =
await authenticationService.verifyPhoneNumber(context, finalNumber);
await authenticationService.verifyPhoneNumber(context, phoneNumber, countryCode);

setState(ViewState.Idle);

Expand Down Expand Up @@ -111,7 +111,7 @@ class LoginModel extends BaseModel {
print('Login With Password successful');
FireStoreService.addUser(
phoneNumber: phoneNumber, countryCode: countryCode);
_sharedPrefsService.setLoggedIn(true);
print(_sharedPrefsService.setLoggedIn(true));
navigationService.navigateTo('home');
} else {
print(user.message);
Expand Down

0 comments on commit df01545

Please sign in to comment.