Search code examples
javascriptember.jsember-cliember-simple-auth

"Ember Simple Auth" invalidateSession from component


Trying to execute this code within a component's template

// components/my-component.js
{{#if session.isAuthenticated}}
  <a {{action 'invalidateSession'}}>Sign out</a>
{{else}}
  {{#link-to 'signin'}}Sign in{{/link-to}}
{{/if}}

However, when clicking "Sign out" button I get this error

Error: <...@component:my-component::ember381> had no action handler for: invalidateSession

How do I make "invalidateSession" available from a component?


Solution

  • You can just implement your own invalidateSession action:

    actions: {
      invalidateSession: function() {
        this.get('session').invalidate();
      }
    }
    

    or simply forward the action from the component to the route:

    {{my-component invalidateSession='invalidateSession'}}