Ad
How To Keep The User Logged In Or Check If The User Is Logged In Or Not In Shopify?
Hi I used the following code to login a user in Shopify.
NSArray *items = @[[BUYAccountCredentialItem itemWithEmail:email], [BUYAccountCredentialItem itemWithPassword:password]];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items];
[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer * customer, BUYCustomerToken * token, NSError * _Nullable error) {
if (customer && !error) {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:token.accessToken forKey:@"CustomerToken"];
[prefs setInteger:[token.customerID integerValue] forKey:@"CustomerId"];
[prefs synchronize];
NSLog(@"Success fully loged in token %@ %@",token.accessToken,token.customerID);
UINavigationController *navigationController = self.navigationController;
[navigationController popViewControllerAnimated:YES];
}else{
[self showEror:@"LogIn Failed" message:@"Please provide valid Details"];
}
}];
Every time I have to login and proceed further. I stored token and customerId in local. How can I make sure that user automatically log in when app opens unless they doesn't logout. Thank you.
Ad
Answer
As you are storing CustomerToken
in your NSUserDefault
, in didFinishLaunchingWithOptions
check the value of CustomerToken
if there is any value in it navigate the user to your Home Screen if there is not any value in it then navigate the user to your Login Screen.
Also, make sure while logging out, you will clear the value from NSUserDefault
Ad
source: stackoverflow.com
Related Questions
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?
Ad