Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async initialize () {
const redis = api.redis.clients.client
api.session = {
prefix: 'session:',
ttl: 60 * 60 * 24, // 1 day
load: async (connection) => {
const key = api.session.prefix + connection.fingerprint
const data = await redis.get(key)
if (!data) { return false }
return JSON.parse(data)
},
create: async (connection, user) => {
const key = api.session.prefix + connection.fingerprint
const randomBuffer = await util.promisify(crypto.randomBytes)(64)
async initialize () {
const redis = api.redis.clients.client
api.blog = {
separator: ';',
postPrefix: 'posts',
commentPrefix: 'comments:'
}
api.blog.postAdd = async (userName, title, content) => {
const key = api.blog.buildTitleKey(userName, title)
const data = {
content,
title,
userName,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
async initialize () {
const redis = api.redis.clients.client
api.users = {}
api.users.add = async (userName, password) => {
const savedUser = await redis.hget(this.usersHash, userName)
if (savedUser) { throw new Error('userName already exists') }
const hashedPassword = await api.users.cryptPassword(password)
const data = {
userName: userName,
hashedPassword: hashedPassword,
createdAt: new Date().getTime()
}
await redis.hset(this.usersHash, userName, JSON.stringify(data))
}