Meteor Auto Logout [Solved]


#1

Hi,

Does anyone have a simple way to do timed log outs in Meteor. Say I want to kick a user out after 30mins of inactivity etc?

Thanks so much.

Tat


loginExpirationInDays - set per user
#2

A package is available for this: Meteor Stale Session https://github.com/lindleycb/meteor-stale-session


#3

You can use Accounts.config:

Accounts.config({
    loginExpirationInDays: 0.02
})

#4

this actually looks really good, is exactly what I need. Where would you use it though?

From here, you can use it anywhere, but where would you put it? Cause it seems to be a global setting, i.e. not per user.

If it was per user, I’d put it in the insertUser method, (i.e. the other place I use accounts (Accounts.createUser), but this does not seem correct). Alternately, I can put it in the admin fixture user, but this seems clunky also.

How do you use it? On a server side global settings - does not make senese to put it with the settings-deployment.json file?

Much appreciated.

Tat


#5

I put it in \imports\startup\server\accounts.js

import { Accounts } from 'meteor/accounts-base'

Accounts.config({
    loginExpirationInDays: 1
})

#6

Much appreciated - thanks so much. While totally obvious, it did not occur to me at all. Doh!


#7

I’m running an Angular/Meteor project and I added an accounts.ts file and configured loginExpirationInDays = null to see if/when it times out.

On localhost it’s been logged in for hours, however when I push the file to the server using mup, it seems to time out after over an hour of being logged in.

Any thoughts?

Second question, do you know how to get it to route to the main login screen when the login expires?

Thanks!


#8

In: app/imports/startup/client/accounts.js, I used (note old v of react-router, don’t use the push):

import { Accounts } from 'meteor/accounts-base';
import { browserHistory } from 'react-router';

Accounts.onLogout(() => {
  browserHistory.push('/login');
});

#9

I base on Meteor + Vue

// Server
import { Accounts } from 'meteor/accounts-base'

Accounts.config({
    loginExpirationInDays: 0.02
})
--------------
// Client
import { Accounts } from 'meteor/accounts-base';

Accounts.onLogout(() => {
  console.log('logged out') // But don't show anything
});

After I refresh page, should it logout to route /logout