1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- module.exports = {
- friendlyName: 'Logout',
- description: 'Log out of this app.',
- extendedDescription:
- `This action deletes the \`req.session.userId\` key from the session of the requesting user agent.
- Actual garbage collection of session data depends on this app's session store, and
- potentially also on the [TTL configuration](https://sailsjs.com/docs/reference/configuration/sails-config-session)
- you provided for it.
- Note that this action does not check to see whether or not the requesting user was
- actually logged in. (If they weren't, then this action is just a no-op.)`,
- exits: {
- success: {
- description: 'The requesting user agent has been successfully logged out.'
- },
- redirect: {
- description: 'The requesting user agent looks to be a web browser.',
- extendedDescription: 'After logging out from a web browser, the user is redirected away.',
- responseType: 'redirect'
- }
- },
- fn: async function (inputs, exits) {
- // Clear the `userId` property from this session.
- delete this.req.session.userId;
- // Then finish up, sending an appropriate response.
- // > Under the covers, this persists the now-logged-out session back
- // > to the underlying session store.
- if (!this.req.wantsJSON) {
- throw {redirect: '/login'};
- } else {
- return exits.success();
- }
- }
- };
|