I am using react-native-fbsdk to login through facebook on my react-native app.
I call LoginManager.logOut() to logout: it does not actually properly logout since the next time I try to login, it does not ask me for login/password again so I can only login on one account. I can not find a way to login to another facebook account.
This guy (react-native-fbsdk: How properly log out from facebook?) had the same problem and seem to have found no solution.
One trick on iOS is to go to safari then logout from the mobile facebook website. This does not work on android though :(
EDIT:
Here is my facebook login code:
function login() {
return LoginManager.logInWithReadPermissions(FACEBOOK_PERMISSIONS)
.then(result => {
if (result.isCancelled) {
throw new Error("Login canceled");
}
return AccessToken.getCurrentAccessToken();
})
.then(({ accessToken }) => accessToken);
}
Video of logout/login: https://d3vv6lp55qjaqc.cloudfront.net/items/132L2U1p383E1y0l2l2v/Screen%20Recording%202018-10-31%20at%2002.52%20PM.mov
So I found this solution, that is not a hack but the proper way to perform a logout on facebook. You need to create a GraphRequest to ask a deletion of permissions.
Below the code, I hope that will help you. I test it on Android and IOS, and that work like a charm.
FBLogout = (accessToken) => {
let logout =
new GraphRequest(
"me/permissions/",
{
accessToken: accessToken,
httpMethod: 'DELETE'
},
(error, result) => {
if (error) {
console.log('Error fetching data: ' + error.toString());
} else {
LoginManager.logOut();
}
});
new GraphRequestManager().addRequest(logout).start();
};
The problem is not with react-native-fbsdk but with Facebook or the browser through which the user logs in to connect to your app, the reason being every-time your app accesses the Facebook login through the browser or the Facebook app where the user-account is already logged-in, which is why it doesn't show you username or password fields.
To solve this issue, the user must logout from the browser or Facebook through which he/she logged in (for app permission initially) to your app, so when the user comes back to your app and selects the Facebook-login option, assuming user logged-out of your app as well, then he/she can see it redirecting to the Facebook or browser login page with username and password fields.
Related
I am trying to login with facebook using Supabase on ios emulator. After logging in with Facebook, it redirects me back to localhost. I don't know exactly what to do on this side. Can you help me? I'm still very new.
const onHandleLogin = async () => {
const {data, error} = await supabase.auth.signInWithOAuth({
provider: 'facebook',
});
if (error) {
return;
}
if (data.url) {
const supported = await Linking.canOpenURL(data.url);
if (supported) {
await Linking.openURL(data.url);
}
}
};
After the login process, it still stays on the localhost address on the browser. My purpose is to send it to the application and get token information via the url, but I have no idea how.
I think I need to make changes here but I don't know what to write in the site url because it is a mobile application.
Thanks for your support and replies.
I tried to login with facebook using supabase, but after logging in, it keeps me in safari and gives token information on localhost. I want to direct the application after the login process and get the token information.
You will need to create a deep link for your React Native app: https://reactnative.dev/docs/linking and then set this as your redirect URL. Here a similar example with Flutter: https://supabase.com/docs/guides/getting-started/tutorials/with-flutter#setup-deep-links
Im trying to add a logout functionality to my mern app where I only have google authentication using passportJS. I want to clear the cache and cookies on logout because if I don't it automatically logs me back in without asking for what account to choose.
The cookie im trying to delete is a https only cookie
I have tried what seems like every solution on the internet but none of them work
logout
document.cookie = "connect.sid=; Max-Age=0;secure;path=/"; // This worked only for the first time
// clears cache which works fine
caches.keys().then((names) => {
names.forEach((name) => {
caches.delete(name);
});
});
window.open(`${apiURL}/auth/logout`, "_self");
I have tried other solutions like: react-cookie, universal-cookie, js-cookie etc... But none of them seem to work either.
Does anyone know how to do this I have been stuck on this for a long time?
Ok so after a while I figured out that I cannot delete http only cookies so what I did was I simply used the req.logout() function on the backend to delete it
when you log the user out you simply redirect the user to this route which then deletes the cookie and redirects back!
router.get("/logout", (req: Request, res: Response) => {
req.logout({}, (err: any) => {
if (err) return res.status(500).json({ message: "Something went wrong." });
res.redirect(clientURL);
});
});
I'm using React Native 0.61.5 with react-native-fbsdk 2.0.0. Facebook app is Live and configured.
The problem is with the Facebook Login when the permission is removed, facebook cannot re-authorise the Facebook Login anymore and keep displaying error in the facebook app.
error message with Facebook App already signed-in and try to use facebook login
Above was just one of the test case. Prior to "Removing" the app permission in Facebook, the facebook login seems to be fine.
This is the basic RN code for Facebook Login
<LoginButton
onLoginFinished={
(error, result) => {
if (error) {
console.log("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => console.log("logout.")}/>
Any of you have any clue or solution?
I'm expecting that the facebook login will re-authorize again but it's not.
Please try adding permissions to the LoginButton like this. So that login button will look for the permissions too. Let me know if facebook re autorize for you..
<LoginButton
permissions={["email", "user_friends", "public_profile"]}
onLoginFinished={this._onFacebookLoginFinished.bind(this)}
onLogoutFinished={this._onFacebookLogoutFinished.bind(this)}
/>
Thank you #imjaad for your attempt to answer my question.
I've resolved this by appealing on Facebook App which the app was Lived, but it has a message that "some of the functions are being restricted".
So, even if Facebook App is Live, make sure there is nothing else / warning / error message that shows up.
I tried to create another Facebook App and it was working fine as well. So nothing wrong with the fbsdk, rn or the code itself.
It was just rare event in Facebook while the appeal is in progress, the Facebook QC made it live temporary, but the message that the app is still being restricted still appear.
So make sure your FB App is Live and there is no other error / warning message in your Facebook App Dashboard.
Good Luck!
My app is using Instagram's REST API, in order for a user to logout and login with a different account I have to clear the cookies for www.instagram.com from the browser. I have been using react-native-cookie with RN 0.59.10 and it has been working fine.
After upgrading to RN 0.60 I can't use the react-native-cookie or any of its alternate packages because they don't support auto-linking. The solution I have found is using the RCTNetworking module from the react-native library. You can see the solution here.
Code
var RCTNetworking = require('RCTNetworking');
export const logout = () => {
return new Promise((resolve, reject) => {
RCTNetworking.clearCookies(result => {
if (!result) {
console.log('Error Message');
reject()
}
store.dispatch({ type: "RESET_APP_STATE" });
NavigationService.navigate("AuthLoading");
resolve()
});
});
};
The code runs fine. The app's state is cleared and the user is navigated to the login screen, but when I open the Instagram page in the webView instead of asking for the username and password, it directly logs me in.
You should use the community-version of react-native-cookies which can be found here: https://github.com/react-native-community/react-native-cookies
I am happily using this in combination with version 0.61.5 of React-Native.
We dont want the user to log in each time he/she opens our Sencha 2 app. Its not determined yet if we will serve it through a web browser or package it as a native app with the Sencha build tool.
Any advices how to solve it? Should I use some local storage to remember if user has logged in?
I have created a Simple Login project on github to illustrate how I'm using localStorage in credential saving. Feel free to use ideas in your project. Feedback & comment are welcome
Cheers, Oleg
Here i am going to save the username and password values with the id of 'ext-record-2'.
if (values.keepUser) {
var user = Ext.create('MyApp.model.LoginLocalSave', {
id: 'ext-record-2',
uemail: values.uname,
pword: values.pword,
isRemember: values.keepUser
});
user.save();
}
On launching of login screen we need to read the username and password fields from the local storage by using the previously save id 'ext-record-2' and display it on the fields.
launch: function() {
var User = Ext.ModelMgr.getModel('MyApp.model.LoginLocalSave');
User.load('ext-record-2', {
success: function(user) {
Ext.ComponentQuery.query('formpanel #uname')[0].setValue(user.get('uemail'));
Ext.ComponentQuery.query('formpanel #pword')[0].setValue(user.get('pword'));
Ext.ComponentQuery.query('formpanel #keepUser')[0].setValue(user.get('isRemember'));
},
failure: function() {
console.warn('Auto-fill login failed.');
}
});
},
Please visit the below url for full source code by clicking the link. [Solved by solution]
http://saravanakumar.org/blog/2014/04/login-screen-with-username-and-password-remember-in-sencha-touch/