getContext()
Environment: server.
getContext()
enables telefunctions to access contextual information.
It's most commonly used for implementing permissions, see Guides > Permissions.
Provide
Before we can use getContext()
, we need to provide the context
object to Telefunc's Server Middleware:
Access
If you get this error:
[telefunc][Wrong Usage][getContext()] Cannot access context object, see https://telefunc.com/getContext#access
Then this means that getContext()
was called after an await
operator:
Make sure to call getContext()
before any await
operators:
TypeScript
We can use Telefunc.Context
to globally set the type of const context = getContext()
:
We can also directly set const context = getContext<MyContext>()
: