Skip to content

Commit

Permalink
fixup! fix instructions for accessing the current user
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Jan 20, 2020
1 parent f4afea7 commit 36fbdae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/site/migration/models/remoting-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ This remoting hook can be rewritten to a LoopBack 4 interceptor as follows:
```ts
class WarnAnonymousInterceptor implements Provider<Interceptor> {
constructor(
@inject.getter(SecurityBindings.USER)
@inject.getter(SecurityBindings.USER, {optional: true})
private getCurrentUser: Getter<UserProfile>,
) {}

Expand All @@ -526,3 +526,11 @@ class WarnAnonymousInterceptor implements Provider<Interceptor> {
}
}
```

Please note the current user must be injected as an optional value, because the
value is available for authenticated endpoints only. In a typical application,
not all endpoints are decorated with the `@authenticate` decorator. If you leave
the injection as required (that's the default), then you will get a binding
error when an unauthenticated endpoint is accessed. See
[Using the Authentication Decorator](../../Loopback-component-authentication.html#using-the-authentication-decorator)
for more details.

0 comments on commit 36fbdae

Please sign in to comment.