Team metadata & client read only metadata (#196)

* added team metadata

* added client readonly metadata

* updated tests

* added team client meta data tests

* added user metadata tests

* added client read only metadata to stack-app

* added client read only metadata
This commit is contained in:
Zai Shi
2024-08-20 20:39:13 +02:00
committed by GitHub
parent 926fd84983
commit 7b5d0ed793
16 changed files with 369 additions and 13 deletions
+17 -1
View File
@@ -151,7 +151,7 @@ console.log(user.clientMetadata);
If you want to store sensitive information, you can use the `serverMetadata` field. This data is only readable & writable from the server.
```tsx title="my-server-component.tsx"
```tsx
const user = await stackServerApp.getUser();
await user.update({
serverMetadata: {
@@ -164,6 +164,22 @@ const user = await stackServerApp.getUser();
console.log(user.serverMetadata);
```
If you want to store some information that is writable by the server but only readable by the client, you can use the `clientReadOnlyMetadata` field. This is useful for things like subscription status, where the client needs to know the status but shouldn't be able to change it.
```tsx
// On the server:
const user = await stackServerApp.getUser();
await user.update({
clientReadOnlyMetadata: {
subscriptionPlan: "premium",
},
});
// On the client:
const user = useUser();
console.log(user.clientReadOnlyMetadata);
```
## Signing out
You can sign out the user by redirecting them to `/handler/sign-out` or simply by calling `user.signOut()`. They will be redirected to the URL [configured as `afterSignOut` in the `StackServerApp`](/sdk/stack-app).