canDelValue
The canDelValue
method lets you allow or disallow deletions of a Value
stored on the server, as sent from a client.
canDelValue(
valueId: string,
connection: Connection,
): Promise<boolean>
Type | Description | |
---|---|---|
valueId | string | |
connection | Connection | |
returns | Promise<boolean> |
This is one of the functions use to sanitize the data that is being sent from a client. Perhaps you might want to make sure the server-stored data adheres to a particular schema, or you might want to make certain data read-only. Remember that you cannot trust the client to only send data that the server considers valid or safe.
This method is passed the Value
Id
that the client is trying to delete. The connection
parameter will be the web socket connection of that client. You can, for instance, use this to distinguish between different users.
Return false
from this method to disallow this Value
from being deleted on the server, or true
to allow it. The default implementation returns true
to allow deletion.
Example
The following implementation will strip out any attempts by the client to delete the 'userId' Value
:
import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
export class MyServer extends TinyBasePartyKitServer {
canDelValue(valueId) {
return valueId != 'userId';
}
}
Since
v4.3.12