-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configurable tokens in nextjs app example (#666)
* feat: allow configurable tokens in nextjs app example * added example for using TokenScopes functions to get token permissions * update default token scope for nextjs app * created separate line in the config example comment * fix: small wording change
- Loading branch information
Showing
5 changed files
with
88 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/web/nextjs-chat/src/app/api/momento/token/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
AllDataReadWrite, | ||
ExpiresIn, | ||
TopicRole, | ||
CacheRole, | ||
TokenScope, | ||
AllTopics, | ||
AllCaches, | ||
TokenScopes | ||
} from "@gomomento/sdk"; | ||
|
||
/** | ||
* First, set the scope of permissions for your tokens. | ||
* | ||
* AllDataReadWrite provides read and write permissions to all of your caches: | ||
* export const tokenPermissions: TokenScope = AllDataReadWrite; | ||
* | ||
* TokenScopes provides several functions that will return the permissions you | ||
* request for a given cache and topic name. | ||
* export const tokenPermissions: TokenScope = TokenScopes.topicPublishSubscribe("your-cache-name", AllTopics); | ||
* | ||
* You can also set it to allow subscriptions to topics in all caches if you prefer: | ||
* export const tokenPermissions: TokenScope = TokenScopes.topicPublishSubscribe(AllCaches, AllTopics); | ||
* | ||
* You may also provide a bespoke list of permissions for each cache and topic that you have: | ||
* export const tokenPermissions: TokenScope = { | ||
* permissions: [ | ||
* { | ||
* role: CacheRole.ReadWrite | CacheRole.ReadOnly, | ||
* cache: AllCaches | "your-cache-name" | ||
* }, | ||
* { | ||
* role: TopicRole.PublishSubscribe | TopicRole.SubscribeOnly, | ||
* cache: AllCaches | "your-cache-name", | ||
* topic: AllTopics | "your-topic-name" | ||
* } | ||
* ] | ||
* }; | ||
* | ||
* More information here: https://docs.momentohq.com/develop/api-reference/auth-tokens#tokenscope-objects | ||
*/ | ||
export const tokenPermissions: TokenScope = TokenScopes.topicPublishSubscribe(AllCaches, AllTopics); | ||
|
||
/** | ||
* Second, set the TTL for your tokens in terms of seconds, minutes, hours, | ||
* days, or using epoch format. You may also set tokens to never expire. | ||
* More information here: https://docs.momentohq.com/develop/api-reference/auth-tokens#generateauthtoken-api | ||
*/ | ||
export const tokenExpiresIn: ExpiresIn = ExpiresIn.minutes(30); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters