NitonFx
NitonFx
Explore posts from servers
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
@Brendonovich do you have any (more) information about the isolation you talked about. Are there solid-start primitives to bypass this isolation createServerSideResource() or something like that?
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
You can access it with getCookie in any server function
Yes this works, i store the key to the map in there (a uuid with httpOnly) and both "use server" and api route can use it
But i don’t think the auth service sends the token to an api route but rather an api route - which is called by the client - should request the token and then pass the token in a httpOnly and secure cookie as a response to the client.
Yes and no the server is a OAuth server so he sends me an url which i call with all the security verifiers etc and get the tokens, introspections and so on. But the tokenset and data i get back from the auth server is rly rly big thats why i refrained from storing all that in the cookie (even encrypted) since the cookie would have around ~2kb which is a little bit much?
Regarding the login flow you should probably stick to an example provided by the auth service’s docs.
Thats what i am trying to do. They state that it is best practice to not expose the access and refresh tokens from the response to the client (and if rly neccesary only encrypted which is what vinxis useSession would do if i understand right)
The with-auth example is great. It shows how to use vinxi‘s session. The password is just a random string for encryption of the cookie value which is typically an env variable.
If implementing a shared store/object/map between a "use server" function and an api route as Brendonovitch pointed out is not possible i will have to fall back to this
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
Maybe i am missunderstanding. So here is pseudocode-ish what i tried: src/routes/api/login_callback.ts
import { myglobalmap } from "~/lib/myglobalmap"
export function GET(event: APIEvent) {
const apiKey = completeOAuthHandshake(event);
myglobalmap.set("some-key", apiKey);
setCookie("globalmapkey","some-key");
}
import { myglobalmap } from "~/lib/myglobalmap"
export function GET(event: APIEvent) {
const apiKey = completeOAuthHandshake(event);
myglobalmap.set("some-key", apiKey);
setCookie("globalmapkey","some-key");
}
src/lib/myglobalmap.ts
export const myglobalmap = new Map<string, OAuthKeyset>;
export const myglobalmap = new Map<string, OAuthKeyset>;
src/lib/useThirdPartyApi.ts
import { myglobalmap } from "~/lib/myglobalmap"

function callThirdPartyApi(){
"use server";
var thirdPartyApiKey = myglobalmap.get(getCookie("globalmapkey")).apiKeyXYZ;
return thirdParyClient.call(thirdPartyApiKey);
}
import { myglobalmap } from "~/lib/myglobalmap"

function callThirdPartyApi(){
"use server";
var thirdPartyApiKey = myglobalmap.get(getCookie("globalmapkey")).apiKeyXYZ;
return thirdParyClient.call(thirdPartyApiKey);
}
and in a component you would use callThirdPartyApi() . But callThirdPartyApi() cannot read the value added to the myglobalmap I am not sure how i would apply your cache() and useAction createAction with this. I tried keeping is at short and trimmed down as possible also i wrote the code in discord so many imports missing
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
@Madaxen86
by using createAsync with a function that uses the "use server" directive an API route will automatically be created.
But i cannot control the api path its always _server ? My oauth server requires me to have a url /api/login_callback that it can deliver the token to. Or do you mean using an use server function inside the api GET handler so the server RPC calls himself and therefore can access the object/cache/session store bound to the "RPC scope"? Regarding vinxi useSession i tried to but the documentation didn't state at all what the password is how to generate, handle, rotate ... it securely and so on so i was pretty sure its beta feature; especially when its a security related feature. Also i was concerned about "replacability" how easy could i change to store to redis or postgres but i should maybe try it again?
16 replies
SSolidJS
Created by Mr Void on 9/16/2024 in #support
Reset signals when prop value changes
i mean one should not read a prop in the main body of the component afaik wouldn't this be cleaner
const Card = (props) => {
createEffect(on(props.data, (_) => {
setShowFront(true)
}))
}
const Card = (props) => {
createEffect(on(props.data, (_) => {
setShowFront(true)
}))
}
8 replies
SSolidJS
Created by jrainearwills on 9/17/2024 in #support
Client Only - Local Storage
which you can then use
createLocalStore("item", str => str.split("|"), obj => `${obj[0]}|${obj[1]}`);
createLocalStore("item", str => str.split("|"), obj => `${obj[0]}|${obj[1]}`);
7 replies
SSolidJS
Created by jrainearwills on 9/17/2024 in #support
Client Only - Local Storage
you can use the isServer if you dont need the state to be available and renderable on the server. BUT i think what you are searching for is better suited as a standalone primitive such as the one provided by @solid-primitives or something homemade and simpler
function createLocalStore<T>(key:string, parse: (string)=>T, format: (T)=>string){
if(isServer) return [/*whatever the fallback should be server side*/];
const pair = window.localStorage.getItem(key);
export const [appState, setAppState] = createStore<T>(parse(pair))

createEffect(() => {
if (appState.itemId && appState.accessToken) {
const value = format(appState);
window.localStorage.setItem(key, value);
} else {
window.localStorage.removeItem(key);
}
})
}
function createLocalStore<T>(key:string, parse: (string)=>T, format: (T)=>string){
if(isServer) return [/*whatever the fallback should be server side*/];
const pair = window.localStorage.getItem(key);
export const [appState, setAppState] = createStore<T>(parse(pair))

createEffect(() => {
if (appState.itemId && appState.accessToken) {
const value = format(appState);
window.localStorage.setItem(key, value);
} else {
window.localStorage.removeItem(key);
}
})
}
7 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
So basically what i want to do is having a route /api/login_callback that acts as a oauth callback point. On call i want to store the access tokens inMemory and on subsequent requests (either "use server"; or an api route) i want to look the user up in this in memory store. Yes as soon as i want to scale it i have to replace it with redis or whatever but i dont need that for now.
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
@Madaxen86 So i saw your example does not use a server route/api route/GET I added such a route and it doesnt work https://stackblitz.com/edit/github-vzswgd-r4ctkn?file=src%2Fapp.tsx
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
I dont think i want to share the internal access key in a cookie readable for the user since the mentioned "Map" is a session store but thanks i will take a look at your example
16 replies
SSolidJS
Created by NitonFx on 9/16/2024 in #support
"use server"; RPC calls cannot access global objects
What would be the best way without a external database be too have a shared cache, map, state or object between these environments then?
16 replies
SSolidJS
Created by Wild on 9/16/2024 in #support
Create one global store with multiple createResource
The first thing that jumps at me is that this would try to execute the SQL on the client/browser. I dont know if thats the issue but it should look like
const items = createResource(async () =>
"use server";
fetchDbData<Item>("SELECT * FROM item;"),
)[0];
const items = createResource(async () =>
"use server";
fetchDbData<Item>("SELECT * FROM item;"),
)[0];
3 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
I am not saying that it is unreasonable to not have such a feature given the already high complexity of meta frameworks
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
But there is no way in general to render something initially on the server and leave it static once on the client
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
Oh like a path /api/myapi/[...path] With like a generic handler that replaces the session with API key and relays it to the real API? Altho I probably would have to be quite careful since well requests have quite a lot to them🤔 Or is the mechanism you mean something different?
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
Backend being solid start server
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
As I said I have a session cookie and only the backend knows the access token
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
Yes
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
Hmmm ok because the problem i have is i have an api client this api client object contains the api key (oath access token) i wanted to do something like
const myClient = useMyClient();
<div>{myClient.getFooBar("lorem ipsum")}</div>
const myClient = useMyClient();
<div>{myClient.getFooBar("lorem ipsum")}</div>
the problem i dont know how to do this without exposing the apiKey from the myClient to the frontend ofc i could write a own use server function for every method in MyClient but i am looking at an autogenerated API client with ~100 API endpoints & growing of which i use quite a few
26 replies
SSolidJS
Created by NitonFx on 9/10/2024 in #support
Keeping data and code secure and on the server (restrict code to initial render)
but it doesn't cause a RPC call because of solid magic?
26 replies