Invalidates the authentication for the current connection.
Method Syntax
db.invalidate()Example usage
After .invalidate(), the connection has no signed-in user, so a query that needs one is refused. The example below continues from the authenticate() example, where db has authenticated with the token of a record user:
// The record user is present in the $auth parameter
println!("{:?}", db.query("$auth").await?);
db.invalidate().await?;
// No user is signed in, so the query is refused
println!("{:?}", db.query("$auth").await);Example output
IndexedResults { results: {0: (DbResultStats { execution_time: Some(26.458µs), query_type: Some(Other) }, Ok(RecordId(RecordId { table: Table("user"), key: String("ajdvh7uwk0sc79j48liw") })))}, live_queries: {} }
Err(Error { code: -32002, message: "Anonymous access not allowed: Not enough permissions to perform this action", details: NotAllowed(Some(Auth(NotAllowed { actor: "anonymous", action: "process", resource: "query" }))) }) Revoking a refresh token (.refresh(token))
db.invalidate() normally clears the whole session. To revoke only the refresh token carried inside a Token (without invalidating the entire session), call .refresh(token) on the invalidate builder, then await:
// Get a token from signin
let token = db.signin(credentials).await?;
// Later, explicitly revoke the refresh token
db.invalidate().refresh(token).await?;Use this when you need to drop refresh capability for a specific token pair while leaving other session state intact.