Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
}
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
}
}
load: async (connection) => {
const key = api.session.prefix + connection.fingerprint
const data = await redis.get(key)
if (!data) { return false }
return JSON.parse(data)
},
async run (data) {
data.response.success = false
await api.session.destroy(data.connection)
data.response.success = true
}
}