binajmen
binajmen
Explore posts from servers
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
I'm having a hard time figuring out how to solve that..
4 replies
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
I suspect the issue comes from the fact getAdmin() is called at two different places in the AdminLayout(), and that there is some kind of unsync at some point where useSession() does not take into account the cookie from the request, and therefore reply with a different cookie (like the default session created by h3)
4 replies
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
The relevant code snippets are the following:
export const router = {
preload() {
getAdmin();
getVariants();
},
} satisfies RouteDefinition;

export default function AdminLayout(props: ParentProps) {
createAsync(() => getAdmin());
export const router = {
preload() {
getAdmin();
getVariants();
},
} satisfies RouteDefinition;

export default function AdminLayout(props: ParentProps) {
createAsync(() => getAdmin());
export const getAdmin = query(async () => {
"use server";
const authService = new AuthService();
const user = await authService.getUserBySession();
if (!user || !user.is_admin) {
throw redirect("/");
}
return user;
}, "admin");
export const getAdmin = query(async () => {
"use server";
const authService = new AuthService();
const user = await authService.getUserBySession();
if (!user || !user.is_admin) {
throw redirect("/");
}
return user;
}, "admin");
const sessionConfig = {
name: "cockpit",
maxAge: 60 * 60 * 24 * 14,
password: process.env.SESSION_SECRET,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
},
} satisfies SessionConfig;

type Session = {
user_id?: string;
};

function getSession() {
return useSession<Session>(sessionConfig);
}

async getUserBySession() {
"use server";
const session = await getSession();
console.log("getUserBySession: session =", session);
const userId = session.data.user_id;
console.log("getUserBySession: userId =", session.data.user_id);
if (!userId) throw redirect("/login");

const user = await this.userService.getUser(userId);
if (!user) throw this.logout();

const { hashed_password, ...safeUser } = user;
return safeUser;
}
const sessionConfig = {
name: "cockpit",
maxAge: 60 * 60 * 24 * 14,
password: process.env.SESSION_SECRET,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
},
} satisfies SessionConfig;

type Session = {
user_id?: string;
};

function getSession() {
return useSession<Session>(sessionConfig);
}

async getUserBySession() {
"use server";
const session = await getSession();
console.log("getUserBySession: session =", session);
const userId = session.data.user_id;
console.log("getUserBySession: userId =", session.data.user_id);
if (!userId) throw redirect("/login");

const user = await this.userService.getUser(userId);
if (!user) throw this.logout();

const { hashed_password, ...safeUser } = user;
return safeUser;
}
4 replies
SSolidJS
Created by binajmen on 11/1/2024 in #support
`classList` does not seem to apply the classes on render
thank you for your answer 😉
4 replies
SSolidJS
Created by gsoutz on 7/19/2024 in #support
Cant set signal from getting another signal typescript error
set_current(target) should work as well
7 replies
SSolidJS
Created by gsoutz on 7/19/2024 in #support
Cant set signal from getting another signal typescript error
still not sure to understand the end goal of update. it might help if you provided a more complete example as update is used nowhere
7 replies
SSolidJS
Created by gsoutz on 7/19/2024 in #support
Cant set signal from getting another signal typescript error
set_current(() => target()) should work although i'm not sure what you are trying to achieve
7 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
lots of valid suggestion, brains are cooking here ;D
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
can you extend on that? im not sure what your suggestion is 😒
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
the fact you can do vanilla js so easily inside of solid is awesome
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
yeah i forgot that it is.
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
XD
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
ty 🙂
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
i meant having the props defined and just loop on it. probably dozen of solutions to avoid such cryptic solution. however I applaud the way of thinking outside the box 👏
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
it was a good and valid use case for WeakMap ;D
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
the other way around. much cleaner
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
exactly
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
but TIL
45 replies
SSolidJS
Created by binajmen on 7/4/2024 in #support
Is there a way to access children props?
I believe the original need is sneaky as well and could be solved in another manner
45 replies