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 contex
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 called getContext()
after an await
operator:
Make sure to call getContext() before any await
operator:
TypeScript
We can use Telefunc.Context
to globally set the type of const context = getContext()
:
We can also directly set const context = getContext<MyContext>()
: