When a user logins the ionic app, how do I pass the user ID to the pages listed in side menu.. Is there a possibility to send data through navParams?
You have to store user ID in ionic storage when the user is login like this,
First, add Ionic storage in your app,
Then, use ionic storage in login component like this,
// set user ID
storage.set('userID', 'Your_user_ID');
Now, get the user ID in whichever component you want like this,
// get user ID
storage.get('userID').then((val) => {
console.log('user ID', val);
});
Thank you.
Related
We are working on an Ionic app where we use firebase and we allow users to login with facebook.
We decided that the email is a required field for our database.
We are facing that some facebook users don't have an email in her/his account (because they created the account using a phone number, for example).
Currently we know the user data after the user is signed up. Is there any way to know that information before that?
signIanWithFacebook() {
return this.facebook.login(['email']).then(res => {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
// here is where we would like to know if user has email
firebase.auth().signInAndRetrieveDataWithCredential(facebookCredential)
.then(
// here is where we currently know if the user has email or not
(userCred: firebase.auth.UserCredential) => this.handleSocialMediaLogin(userCred)
).catch((err) => this.onLoginError(err));
});
}
I'm developing an application with ionic and Backand and I'm using the sign in with social accounts with the Backand service.
The social login process is OK, but I want to get the ID from Facebook and Google plus in order to get the profile picture.
I was talking with the support of Backand and I know that in Security and Auth there is an action "beforesocialSignUp" and I have not commented the line to get the data:
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
// get facebook id and put in fuid field that you need to add to your user object
userInput.fuid = parameters.socialProfile.additionalValues.id;
// get gender from facebook and put in gender field that you need to add to your user object
// userInput.gender = parameters.socialProfile.additionalValues.gender;
}
And I have created the fuid field in my user object, but, when I make a login with Facebook or Google+ It doesn't save nothing. The login is OK but I can't get the ID data.
Any idea?
I had exactly the same problem.
The solution was to set the where condition of the BeforeSocialSignUp function from false to true.
This is nowhere in the documentation explained.
It took me 3 day ro figure this out :-(
Now the login works as expected and the fuid field gets assigned.
My next step is to get the profile picture from the FB Account, but therefore I have to make an API request to facebook with a user access token which I dont know how to get from backand.
i'am trying to made cordova application that need user login to (google + or Facebook)
so i show button for sign in to (google+ or Facebook)
but after i close the app and open it again i need the sign in button hide depending on last signed in account
i need to know how i can check if user signed after closing my application?
ie check if user subscribe with data login to my app or no?
You can check this when your application gets loaded in
function onDeviceReady() {
// Now safe to use device APIs
//Create small function which check for is access toke valid or not
//which returns Boolean true or false
// Else you can use localStorage.isSignInned and once logged in set it as true.
if(isSignInned)
{
//hide buttons
}
}
You can check facebook javascript api here and google javascript api here
It depends upon how you want your application to work.
I am attaching working sample which i created for Facebook for GooglePlus
hope this helps.!
I've used Auth0 service into my Ionic project to create a login page and it's working with my own-database connection.
All I want to do is to save the data from social(e.g facebook) to my own-database. Is that possible?
I've tried using social login in auth0, but those profile data is saved on my Auth0 account. I need those data to be saved in my own-database.
Yes, you can do that in a rule. Taken from a post at ask.auth0.com:
function (user, context, callback) {
if (context.connectionStrategy === 'connection') {
// store user data in database
}
callback(null, context, callback);
}
As per the documentation in the following link, we can get the user id if the uer will interact with the form..
http://wiki.developers.facebook.com/ind … d_Policies
"If a viewing user interacts with the tab (like submits a form, takes an action that causes an AJAX load of new content, or follows a relative URL that loads on the tab), that user's UID is sent to the application as the fb_sig_user parameter, the profile owner's user ID is sent as the fb_sig_profile_user parameter. The viewing user's session key is key is sent only if the user authorized the application. "
In my fan page tab am I have an AJAX form which the user can submit with some value.. now I need the users id also.. how can I get this..
I tried to get the value in my AJAX submit page using $_POST['fb_sig_user'] with no success.. can anyone help me with this please..
You won't be able to get the id of the user using $_POST['fb_sig_user'] unless you authenticate the user by having this in the facebook's ajax function:
ajax.requireLogin = true;
For example, I'm retrieving it fine with this:
function do_ajax(url, div_id)
{
document.getElementById('poller_waitMessage').setStyle('display', 'block');
var ajax = new Ajax();
ajax.responseType = Ajax.FBML;
ajax.onerror = function(error)
{
new Dialog().showMessage("Error:", "Some communication error occured, Please reload the page.","Ok");
};
ajax.ondone = function(data)
{
document.getElementById('poller_waitMessage').setStyle('display', 'none');
document.getElementById(div_id).setInnerFBML(data);
}
ajax.requireLogin = true; // <----- this is important
ajax.post(url);
}
I've been happily using the form variable fb_sig_profile_user for previous apps, and when developing a new app last week, the variable was no where to be found.
Searched for several days, I was about to give up, and then the found answer:
ajax.requireLogin = true;
I understand FB cares about privacy and all, but they really need to announce these kinds of changes before just taking it away.
Million Thanks!