How to use the actionhero.api.session function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-angular-bootstrap-cors-csrf / actions / session.js View on Github external
async run (data) {
    data.response.success = false
    const sessionData = await api.session.load(data.connection)
    if (!sessionData) { throw new Error('Please log in to continue') }

    const user = await api.models.user.findOne({ where: { id: sessionData.userId } })
    if (!user) { throw new Error('user not found') }

    data.response.user = user.apiData(api)
    data.response.csrfToken = sessionData.csrfToken
    data.response.success = true
  }
}
github actionhero / actionhero-angular-bootstrap-cors-csrf / actions / session.js View on Github external
async run (data) {
    data.response.success = false
    const user = await api.models.user.findOne({ where: { email: data.params.email } })
    if (!user) { throw new Error('user not found') }

    const match = await user.checkPassword(data.params.password)
    if (!match) { throw new Error('password does not match') }

    const sessionData = await api.session.create(data.connection, user)
    data.response.user = user.apiData(api)
    data.response.success = true
    data.response.csrfToken = sessionData.csrfToken
  }
}
github actionhero / actionhero-angular-bootstrap-cors-csrf / initializers / session.js View on Github external
load: async (connection) => {
        const key = api.session.prefix + connection.fingerprint

        const data = await redis.get(key)
        if (!data) { return false }
        return JSON.parse(data)
      },
github actionhero / actionhero-angular-bootstrap-cors-csrf / actions / session.js View on Github external
async run (data) {
    data.response.success = false
    await api.session.destroy(data.connection)
    data.response.success = true
  }
}