Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change FeathersJs cookies expiration time? #439

Closed
cwsdeepak opened this issue Oct 20, 2016 · 10 comments
Closed

How to change FeathersJs cookies expiration time? #439

cwsdeepak opened this issue Oct 20, 2016 · 10 comments

Comments

@cwsdeepak
Copy link

cwsdeepak commented Oct 20, 2016

I am new in feathersjs. I setup feathersjs with MongoDb my system and its working fine. For my website, I want to modify cookies expiration time (default 30 second). I already checked feathersjs document for this issue. Below is the link: https://docs.feathersjs.com/authentication/readme.html#cookie-options

I also getting an error while executing any query with feathersjs. "Uncaught (in promise) Error: You are not authenticated.".

Can anyone help me in fixing this issue?

Thanks in advance.

@marshallswain
Copy link
Member

I believe you got your answer in the Slack help channel. Did that solve your issue?

As for the "not authenticated" issue, the request is missing the token, more than likely. Are you using Feathers Client or another method of connecting to the server? If you are using the Feathers client, you need to call app.authenticate() before making any other requests. Please let me know how you are connecting and I'll see if I can help more.

@cwsdeepak
Copy link
Author

I used that solution, but its not working for me.

I am using jquery feathers client. I am using following code in my app.js file.

// app.js code
'use strict';

// Establish a Socket.io connection
const socket = io();
// Initialize our Feathers client application through Socket.io
// with hooks and authentication.
const app = feathers()
.configure(feathers.socketio(socket))
.configure(feathers.hooks())
// Use localStorage to store our login token
.configure(feathers.authentication({
storage: window.localStorage
}));

// Get the Feathers services we want to use
const userService = app.service('users');

$('.logout').on('click', function() {
app.logout().then(() => window.location.href = '/admin/');
});

app.authenticate().then((result) => {
console.log(result);
console.log(app.get('token'));
console.log(app.get('user'));
// Find all users
userService.find().then(page => {
console.log(page.data);
});
})
// On errors we just redirect back to the login page
.catch(error => window.location.href = '/login.html');

This code showing me "not authenticated" issue at userService.find(). Also app.get('user') function not returning any details currently logged in user.

Thanks for replaying me.

@cwsdeepak cwsdeepak reopened this Oct 20, 2016
@marshallswain
Copy link
Member

marshallswain commented Oct 20, 2016

Looks like you are using the socketio provider, so the issue is probably related to this: feathersjs-ecosystem/authentication#275 (comment)

Try locking the socket connection to use the websocket transport as is demonstrated there. The next version will automatically take care of this.

@cwsdeepak
Copy link
Author

cwsdeepak commented Oct 21, 2016

I checked that article, but my issue is different. Feather cookies expired, before my code complete its execution. I am trying to fix this issue. If you have any idea about changing expiration time. Please guide me. I am using https://docs.feathersjs.com/authentication/readme.html#cookie-options as reference.

My configure default.json as following:
{ "host": "localhost", "port": 3030, "mongodb": "mongodb://localhost:27017/beautylynk", "public": "../public/", "auth": { "token": { "secret": "WFIGbptkfYrX1OV41/FyaiE25n5mZjSeEgO5GAalWriqY5LcIFgf5x8bVv3eE58ocD69Y5oP76OP48kM0D2Wdg==" }, "local": {}, "cookie": { "name": "BeautyLynk", "expires": "10d" }, "successRedirect": "/admin/dashboard.html" } }

@marshallswain
Copy link
Member

Weird. I thought I just fixed this in the docs, but I guess it got lost. It uses Express cookie settings, so change 'expires' to 'maxAge'

@ekryski
Copy link
Contributor

ekryski commented Oct 21, 2016

@cwsdeepak @marshallswain's suggestion works with newer beta versions of auth but if you are usin v0.7.x you can hack around it by setting auth.cookie.expires to a future date in code right before you initialize your authentication service. maxAge is not supported < 0.8.

Sorry it's kind of hack will be much easier in the 1.0 version of auth.

@cwsdeepak
Copy link
Author

@marshallswain @ekryski I checked my package.json and find out that I am using 0.7.11 version of feathers-authentication.

@ekryski
Copy link
Contributor

ekryski commented Oct 24, 2016

@cwsdeepak ok cool. Try you need to do what I mentioned above. Try this:

let authOptions = app.get('auth');
const now = new Date();
const DAYS = 2;
authOptions.cookie.expires = now.setTime( now.getTime() + DAYS * 86400000 );
app.set('auth', authOptions);
app.configure(authentication(authOptions));

@cwsdeepak
Copy link
Author

@ekryski I used your solution and its working for me. Thanks @ekryski and @marshallswain for helping

@lock
Copy link

lock bot commented Feb 7, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants