canDelTable
The canDelTable
method lets you allow or disallow deletions of a Table
stored on the server, as sent from a client.
canDelTable(
tableId: string,
connection: Connection,
): Promise<boolean>
Type | Description | |
---|---|---|
tableId | 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 Table
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 Table
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 'user' Table
:
import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
export class MyServer extends TinyBasePartyKitServer {
canDelTable(tableId) {
return tableId != 'user';
}
}
Since
v4.3.12