fb.login does not ask email permission - facebook-javascript-sdk

I just called the below codes in my webpage.
FB.init({
appId : 'XXXXXX',
status : true,
cookie : true,
oauth: true,
xfbml : true
});
FB.login(function(response) {
// handle the response
}, {scope: 'email'});
It does not ask permission. Please advice me.

Related

How to keep users logged in after browser close with nuxt auth?

I have the following inside my nuxt.config.js file:
auth: {
strategies: {
local: {
scheme: 'local',
token: {
property: 'meta.token',
global: true,
},
user: {
property: 'data',
},
endpoints: {
login: { url: '/auth/login', method: 'post' },
logout: { url: '/auth/logout', method: 'post' },
user: { url: '/auth/user', method: 'get' }
}
},
}
},
After a short (but still unknown amount of time for me), user is logged out. Also, after closing and opening the browser, user is always logged out. How could I persist the logged in state even after closing the browser? Also, why could be the reason for users be logged out after a short amount of time?
Inspecting cookies I have in my bearer token:
Expires / Max-Age:"Session"
And I have in my local storage:
auth._token_expiration.local:"1656703495434"
Using this.$auth.$storage.setUniversal('user', response.data, true) was enough to solve OP's issue.
As shown here: https://auth.nuxtjs.org/api/storage/#universal-storage

Nuxtjs. loggedIn is still false after setUser

I have two websites. On the first the user logs in (creating a local storage value), on the second (the one I am trying to program) the storage value is rechecked for login but is returning false. What do I need to modify?
NB: I know this is a strange situation, but there is a reason for it so it cannot be changed.
In strategies I have...
local: {
token: { required: false, maxAge: 90000 },
user: { autoFetch: false, property: false },
endpoints: {
user: false,
login: false,
logout: false,
},
},
... property being set to false as the storage value is a more complex version of {"firstName":"abc","lastName":"def"}, i.e. not in a user field.
In the main vue file I have...
created() {
var savedData = localStorage.getItem("ngStorage-user");
if (savedData !== null) {
alert(savedData); // Displays the string that I expect.
this.$auth.setUser(JSON.parse(savedData)); // The setUser call.
alert(this.$auth.user.firstName); // Displays 'abc'.
alert(this.$auth.loggedIn); // Displays false
}
}
PS: I have reviewed the similar queries, but none seems to match this.
====
Addendum: I have possibly solved this, and improved it at the same time by checking that the token is valid.
Added a call to tokencheck in the API which checks the token and returns minimal user details.
local: {
token: { required: false, maxAge: 90000, property: "token" },
user: { autoFetch: false, property: false },
endpoints: {
user: { url: `${process.env.API_URL}tokencheck` },
login: false,
logout: false,
},
},
And then in Vue
created() {
var savedData = localStorage.getItem("ngStorage-user");
if (savedData !== null) {
var parsedSaveData = JSON.parse(savedData);
this.$auth.setUserToken(parsedSaveData.token) // Which calls the 'user' endpoint
.then(res => { this.$auth.setUser(res.data); })
.catch(() => { this.error = true; });
}
}

Nuxt Auth Module c5 doesn't refresh token automatically when token expires

Version
module: 5.0.0-1624817847.21691f1
nuxt: 2.15.8
Nuxt configuration
Universal
Nuxt configuration
// Auth: https://auth.nuxtjs.org/ (v5)
auth: {
redirect: {
login: '/account/login/',
logout: '/account/login/',
callback: '/account/login/',
home: '/account/beams/'
},
strategies: {
local: {
scheme: 'refresh',
token: {
property: 'access_token',
maxAge: 120, // seconds, 2 minutes
global: true
},
refreshToken: {
property: 'refresh_token',
data: 'refresh_token',
maxAge: 1209600 // seconds, 2 weeks
},
user: {
property: 'user',
autoFetch: true
},
endpoints: {
login: { url: '/api/account/login', method: 'post', propertyName: 'token' },
refresh: { url: '/api/account/refresh', method: 'post', },
logout: { url: '/api/account/logout', method: 'post' },
user: { url: '/api/account', method: 'get' }
},
autoLogout: false
}
}
},
Additional information
Checklist
[x] I have tested with the latest Nuxt version and the issue still occurs
[x] I have tested with the latest module version and the issue still occurs
[x] I have searched the issue tracker and this issue hasn't been reported yet
Steps to reproduce
What is expected?
When a user's token expires and refresh scheme is implemented, a user shouldn't be logged out and redirected back to the login screen, the refresh token should be used to obtain a new token and the transition should be seamless allowing any authenticated route to continue to work.
What is actually happening?
In my Nuxt project with the Auth module I've implemented the refresh scheme, however, when my token expires I don't see any request in my network being made to the refresh route after my token expires and I navigate to a protected page via the auth middleware.
I expect I'm missing some simple configuration?
My current token has an expiry of 1 minute for testing, and my refresh token has an expiry of 14 days for testing.
However, when adding:
scheme: 'refresh'
refresh: { url: '/api/account/refresh', method: 'post', }
the functionality appears to not be fetching my user and automatically logging me in.
My /api/account/refresh endpoint in my API returns the following:
{
refresh_token: 'my refresh token',
token_type: 'bearer',
expired_in: 5000
}
My /api/account/login endpoint in my API returns the following:
{
access_token: 'my token',
token_type: 'bearer',
expired_in: 1000
}
What am I missing?
You need to return refresh token from /api/account/login. And then set in conf property name of it.
I have same issue with very similar comfiguration. This is my result from API (I added refresh token to the result):
{
"access_token": "XXX",
"refresh_token": "XXX",
"expired_in": 3600,
"token_type": "bearer"
}
If I inspect cookies, I can see acces token, but refresh token does not set:
I try to manually set refresh token after login, but with same result:
const result = await this.$auth.loginWith('local', {
data: this.login,
})
this.$auth.setUserToken(result.data.accessToken, result.data.refreshToken)

FB.ui response callback not working on mobile device

I have a function that triggers a Facebook share dialogue. When the user has successfully shared a site, the callback function calls a AJAX post that updates a counter in my database (rails). This works fine on desktop but when I test this on a mobile device (Safari), the callback function is not triggered at all:
function shareOnFacebook(){
FB.init({
appId : 'xxxxxx',
xfbml : true,
version : 'v2.5'
});
FB.ui({
method: 'share',
name: 'foo',
picture: 'http://mypic.com',
href: 'http://mypage.com',
description: 'descr'
}, function(response) {
if(response){
$.ajax({
url: "/my-app/post-url",
type: 'POST',
data: {
some_id: 123
}
});
}
else{}
});
}
I digged through the docu but could not find any response on what I am doing wrong. Maybe you guys have a hint. Appreciated.

Disable auto login - facebook javascript SDK

I want to disable auto login in my website when there is a facebook session user. I want the user to click on the facebook login button
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
Just do this.
FB.init({
appId : 'key',
status : false,
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.8' // use graph api version 2.8
});
and auto login will be disabled.
just put status on the top.
Instead of facebook events, simply use FB.Login.
Call the userLogin(), when the user click your Login button (not the facebook login button, but a simple button)
function userLogin()
{
FB.login(function(response)
{
if (response.authResponse)
{
console.log('Welcome! Fetching your information.... ');
var access_token = response.authResponse.accessToken;
location.href = "REDIRECT_TO.php";
}
else
{
console.log('User cancelled login or did not fully authorize.');
}
});
}
So now, the user have to click on the facebook login button every time he visits your site.
Add "status: false" inside your FB.init.
This will prevent an existing Facebook session from logging users in automatically.
https://developers.facebook.com/docs/unity/reference/current/FB.Init