import { createEffect, createResource, createSignal, Show } from "solid-js";
class UserSession extends $session
.params({ id: s.number() })
name: s.title("Name").string(),
password: s.title("Password").string(),
.self({ SessionHandler })
.create(async function (params) {
if (params.name === "admin" && params.password === "admin") {
await this.sessionHandler.set(UserSession, { id: 1 });
throw new Error("Invalid auth");
.self({ SessionHandler })
.create(async function () {
await this.sessionHandler.unset(UserSession);
const fetchSessionData = $api
.title("Try fetch session params")
.create(async function () {
return { id: this.userSession.params.id };
.self({ UserSession: iocParam(UserSession).optional() })
return !!this.userSession;
.api({ login, logout, fetchSessionData, checkAuth })
.params({ name: login.params.name.optional() })
.create(({ api, params }) => {
const [name, setName] = createSignal(params.name ?? "");
const [password, setPassword] = createSignal("");
const logout = createAction(api.logout);
const fetchSessionData = createAction(api.fetchSessionData);
const [checkAuth, { refetch }] = createResource(api.checkAuth);
const login = createAction(api.login).with(() => ({
createEffect(() => logout.state && refetch());
if (login.state === "success") {
<p>checkAuth: {checkAuth.latest ? "true" : "false"}</p>
onClick={fetchSessionData}
disabled={fetchSessionData.running}
children={fetchSessionData.title}
? fetchSessionData.error.message
: fetchSessionData.result
? JSON.stringify(fetchSessionData.result)
<Show when={checkAuth.latest === true}>
disabled={logout.running}
<Show when={checkAuth.latest === false}>
placeholder={login.params.name.options.title}
placeholder={login.params.password.options.title}