colinshen
colinshen
Explore posts from servers
DTDrizzle Team
Created by colinshen on 9/5/2024 in #help
Should I create a global drizzle instance?
1. a global drizzle instance with a global db client 2. a function that return drizzle database instance
1 replies
SSolidJS
Created by colinshen on 4/28/2024 in #support
getRequestEvent not return the correct type in monorepo
I need a package that shared between apps. I add solid-js and @solidjs/start as peerDependencies in the package.json of the package. When I do import { getRequestEvent } from "solid-js/web";, it only returns the type from solid-js/web not the declare module in the solid/start. How can I fix this? Thanks.
1 replies
SSolidJS
Created by colinshen on 4/26/2024 in #support
Render a new router and redirect in action of opened component doesn't redirect in the opened window
Example codes
export function winOpen(provider: string) {
if (window) {
const win = window.open(
"",
"",
);
if (win) {
render(
() => (
<Router
root={() => {
return <SomeComponent />;
}}
/>
),
win.document.body,
);
}
}
}
function SomeComponent(){
const action = useAction(someaction);
}
const someaction = action(async(){
return redirect("https://www.google.com")
})
export function winOpen(provider: string) {
if (window) {
const win = window.open(
"",
"",
);
if (win) {
render(
() => (
<Router
root={() => {
return <SomeComponent />;
}}
/>
),
win.document.body,
);
}
}
}
function SomeComponent(){
const action = useAction(someaction);
}
const someaction = action(async(){
return redirect("https://www.google.com")
})
why the redirect took places in the original window tab not in the opened window?
6 replies
SSolidJS
Created by colinshen on 4/15/2024 in #support
Authentication in both component and middleware
After did some search I'm still confused how solid start handles the authentication. In some auth libraries, they are using middleware to protect api routes and actions but not components(middlewares do not get called when route changes). I looked at the auth example, it only applies a simple action, not a layout. I simply created an auth middleware (from lucia example) and protected component, but I think the solution is not clear.
6 replies
SSolidJS
Created by colinshen on 2/22/2024 in #support
multiple layout
Routes folter
(auth).tsx
(auth)
--signin
--signup
(dashboard).tsx
(dashboard)
--index (default home page)
(auth).tsx
(auth)
--signin
--signup
(dashboard).tsx
(dashboard)
--index (default home page)
I found this works. The default index page is in dashboard folder. I'm confusing now. Parenthesis are used to rename index page, but, in my case, I have both (auth).tsx and (dashboard).tsx. Why the dashboard worked?
1 replies
SSolidJS
Created by colinshen on 2/6/2024 in #support
confused about primitives(useEffect,on,createComputed)
I‘m trying to create a primitive for synchronize the search params with signal. I tried different methods, all of them works as expected. I started to think of the apis and got confused. createEffect in this case run twice createEffect with on run once createComputed run twice 1. why some of them run twice? 2. when to use on with effect? 3. tracking signal and do some updates, shoud I just use computed?
export function createSearchParameter(param: string): Signal<ParamsValue> {
const [searchParams, setSearchParams] = useSearchParams();
const [value, setValue] = createSignal<ParamsValue>(searchParams[param]);
createEffect(
on(value, (v) => {
console.log("create effect on");
setSearchParams({
...searchParams,
[param]: v,
});
}),
);
createEffect(() => {
console.log("create effect");

setSearchParams({
...searchParams,
[param]: value(),
});
});
createComputed<Accessor<ParamsValue>>((v) => {
console.log("createComputed");

setSearchParams({
...searchParams,
[param]: v(),
});
return v;
}, value);
return [value, setValue];
}
export function createSearchParameter(param: string): Signal<ParamsValue> {
const [searchParams, setSearchParams] = useSearchParams();
const [value, setValue] = createSignal<ParamsValue>(searchParams[param]);
createEffect(
on(value, (v) => {
console.log("create effect on");
setSearchParams({
...searchParams,
[param]: v,
});
}),
);
createEffect(() => {
console.log("create effect");

setSearchParams({
...searchParams,
[param]: value(),
});
});
createComputed<Accessor<ParamsValue>>((v) => {
console.log("createComputed");

setSearchParams({
...searchParams,
[param]: v(),
});
return v;
}, value);
return [value, setValue];
}
11 replies
SSolidJS
Created by colinshen on 1/26/2024 in #support
How to set a cookie that is returned from api call?
I'm using createAsync for a server api call. The api returns data with cookie that I need later.
async function foo(){
"use server";
const res = await callApi();
// how append a cookie here?
return res.data
}
createAsync(()=> foo())
async function foo(){
"use server";
const res = await callApi();
// how append a cookie here?
return res.data
}
createAsync(()=> foo())
I tried appendHeader before return, but I got error Cannot set headers after they are sent to the client.
2 replies
SSolidJS
Created by colinshen on 1/26/2023 in #support
Map return from createServerData
return createServerData$(
async ([params]) => {
const collectionMap = new Map();
const data= await xxx;
for (const db of data.data) {
const collections = await xxx;
collectionMap.set(db.id, collections);
}
return {
data,
collectionMap,
};
},
{
key: () => [props.params],
},
);
return createServerData$(
async ([params]) => {
const collectionMap = new Map();
const data= await xxx;
for (const db of data.data) {
const collections = await xxx;
collectionMap.set(db.id, collections);
}
return {
data,
collectionMap,
};
},
{
key: () => [props.params],
},
);
collectionMap.get("id") cause server error: result(...)?.collectionMap.get is not a function I Cant return map from serverData?
4 replies