mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-20 21:29:36 +08:00
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:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user