@bajtos @superkhau
Consider this Provider (aka Binding)
export class AuthenticatedUser {
constructor(
private @inject('authentication.required') required,
private @inject('http.request') req,
private @inject('authentication.strategy') strategy,
)
static name = 'authentication.user';
async value() {
const user = await this.strategy.authenticate(this.req);
// ...
return user;
}
}
...and this Sequence
class TodoSequence extends Sequence {
constructor(
public @injectAuthenticate() authenticate,
public @injectAuthorize() authorize,
public @injectInvoke() invoke,
public @injectSend() send,
public @injectReject() reject
) {}
async run() {
if(false) {
// this will never execute
await this.authenticate();
}
await this.authorize();
this.send(await this.invoke());
}
}
await this.authenticate();
This code will never run, but the authentication.user value function will. We need some way to ensure that only when authenticate() is called that we resolve the authentication.user binding.
export class Authenticate {
constructor(
private @inject('authentication.required') required,
// this will will be resolved - even if the `authenitcate()` function is never called
private @inject('authentication.user') user
)
static name = 'authentication.user';
value() {
console.log(this.user); // {username: ...};
return () => {
const isAuthRequired = this.required;
const user = this.user;
if (isAuthRequired && !user) {
throw ...;
}
}
}
}
@bajtos @superkhau
Consider this
Provider(aka Binding)...and this
SequenceThis code will never run, but the authentication.user value function will. We need some way to ensure that only when
authenticate()is called that we resolve theauthentication.userbinding.