These functions return information about the current SurrealDB session.
| Function | Description |
|---|---|
session::ac() | Returns the current user’s access method |
session::db() | Returns the currently selected database |
session::id() | Returns the current user’s session ID |
session::ip() | Returns the current user’s session IP address |
session::ns() | Returns the currently selected namespace |
session::origin() | Returns the current user’s HTTP origin |
session::rd() | Returns the current user’s record authentication data |
session::token() | Returns the current user’s authentication token |
session::acAvailable since: v2.0.0
NoteThis function was known as
session::scin versions of SurrrealDB before 2.0. The behaviour has not changed.
The session::ac function returns the current user’s access method.
API DEFINITIONsession::ac() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::ac(); "user"
session::dbThe session::db function returns the currently selected database.
API DEFINITIONsession::db() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::db(); "my_db"
session::idThe session::id function returns the current user’s session ID.
API DEFINITIONsession::id() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::id(); "I895rKuixHwCNIduyBIYH2M0Pga7oUmWnng5exEE4a7EB942GVElGrnRhE5scF5d"
session::ipThe session::ip function returns the current user’s session IP address.
API DEFINITIONsession::ip() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::ip(); "2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF"
session::nsThe session::ns function returns the currently selected namespace.
API DEFINITIONsession::ns() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::ns(); "my_ns"
session::originThe session::origin function returns the current user’s HTTP origin.
API DEFINITIONsession::origin() -> string
The following example shows this function, and its output, when used in a RETURN statement:
RETURN session::origin(); "http://localhost:3000"
session::rdAvailable since: v2.0.0
The session::rd function returns the current user’s record authentication.
API DEFINITIONsession::rd() -> string
session::tokenThe session::token function returns the current authentication token.
API DEFINITIONsession::token() -> string