LIVE SESSION
One auth state, two sides
Create an account or sign in. The CRUD block reads this same Store and enables its protected actions.
Authenticated as
Open CRUD to create, update, and delete with this session.
REGISTER
Password
LOGIN
Password
SERVER BLOCK / AUTH
Auth state shared with Views
Register and login create an opaque ULID session, persist it in Database, cache it for fast validation, and update one shared View Store.
LIVE SESSION
One auth state, two sides
Create an account or sign in. The CRUD block reads this same Store and enables its protected actions.
Authenticated as
Open CRUD to create, update, and delete with this session.
REGISTER
LOGIN
SOURCE FILES
Cache-aside auth without client secrets
The token carries only a ULID. Middleware verifies it through Cache first and Database second; the View Store contains display state and the bearer value, never provider credentials.
import exampleSession from "@/views/store/example-session"
fn login
request result method:"POST" route:"/api/examples/auth/login" body:loginForm
if result.ok
set exampleSession value:result.data
Text show:exampleSession.authenticated
"Authenticated as"
Text show:exampleSession.authenticated
"{exampleSession.user.name}"import ExampleSessionState from "@/views/types/example-session"
store exampleSession:
type:ExampleSessionState
persistent:true
value:{ authenticated:false guest:true authorization:"" token:"" user:{ id:"" name:"" email:"" } }type ExampleSessionUser
id:string
name:string
email:string
type ExampleSessionState
authenticated:bool
guest:bool
authorization:string
token:string
user:ExampleSessionUsermiddleware requireExampleAuth
bearer token value:req.header.Authorization
session verified cache:ExamplesCache database:ExamplesDb token:token maxAge:2592000
if verified.valid
next context:{ auth:{ subject:verified.userId session:verified.id authorization:req.header.Authorization token:token } }
return status:401 json:{ ok:false error:"Unauthorized" }handler registerExampleUser
const body value:req.json
registerExampleUserService result args:{ name:body.name email:body.email password:body.password }
return status:201 json:{ ok:true data:result }
handler logoutExampleUser
logoutExampleUserService result args:{ session:req.context.auth.session }
return json:{ ok:true data:result }fn loginExampleUserService params:{ email:string password:string }
findExampleUserRepository user args:{ email:args.email password:args.password }
createExampleSessionRepository session args:{ userId:user.id }
str authorization source:"join" values:["Bearer" session.id] delimiter:" "
return value:{ authenticated:true guest:false authorization:authorization token:session.id user:{ id:user.id name:user.name email:user.email } }fn createExampleSessionRepository params:{ userId:string }
id session source:"ulid"
query created conn:ExamplesDb.insert table:"sessions" value:{ id:session userId:args.userId createdAt:now } required:["id" "userId"]
str sessionKey source:"join" values:["session" session] delimiter:":"
kv cached conn:ExamplesCache.set key:sessionKey value:{ id:session userId:args.userId }
return value:{ id:session userId:args.userId }database ExamplesDb provider:"dowe" host:env.DOWE_HOST port:env.DOWE_PORT account:env.DOWE_ACCOUNT secret:env.DOWE_SECRET name:"dowe-docs-examples" entities:[ExampleUsers ExampleBlogs Sessions] seeders:[]
cache ExamplesCache provider:"dowe" host:env.CACHE_HOST port:env.CACHE_PORT account:env.CACHE_ACCOUNT secret:env.CACHE_SECRET name:"dowe-docs-examples"entity ExampleUsers
id:string primary:true
name:string required:true
email:string required:true unique:true
passwordHash:string required:true
createdAt:timestamp required:trueentity Sessions
id:string primary:true
userId:string required:true index:true
createdAt:timestamp required:trueid session source:"ulid"
str authorization source:"join" values:["Bearer" session] delimiter:" "
kv cached conn:ExamplesCache.set key:sessionKey value:{ id:session userId:user.id }
return value:{ authenticated:true guest:false authorization:authorization token:session }