You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
942 B
31 lines
942 B
import {Logging, Middleware, Session} from "@extollo/lib"
|
|
import {Inject, Injectable} from "@extollo/di"
|
|
import {User} from "../../../models/User.model";
|
|
|
|
/**
|
|
* InjectUser Middleware
|
|
* --------------------------------------------
|
|
* Put some description here.
|
|
*/
|
|
@Injectable()
|
|
export class InjectUser extends Middleware {
|
|
@Inject()
|
|
protected readonly session!: Session
|
|
|
|
@Inject()
|
|
protected readonly logging!: Logging
|
|
|
|
public async apply() {
|
|
const userId = this.session.get('auth.user_id')
|
|
if ( userId && !this.request.hasKey(User) ) {
|
|
const user = await User.findByKey<User>(userId)
|
|
this.logging.debug(`Looked up user ID ${userId} from session. Found? ${!!user}`)
|
|
if ( user ) {
|
|
this.request.registerSingletonInstance<User>(User, user)
|
|
}
|
|
} else {
|
|
this.logging.verbose(`No user ID defined in session.`)
|
|
}
|
|
}
|
|
}
|