S
SolidJS•5mo ago
zimo

"[error] UnknownAction" on getSession() in AuthJS

Hello, I have tried to follow the example here on using @solid-mediakit/auth: https://www.npmjs.com/package/@solid-mediakit/auth#server-side I have implemented it as suggested but I am having trouble using getSession(). In previous versions I have used it in server-side db methods like this:
export const fetchCountryInfoServer = server$(async (countryId: string) => {
const session = await getSession(server$.request, authOptions);
const user = await getAndVerifyUser(session);

return await prisma.country.findFirst({ where: { userId: user.id } });
});
export const fetchCountryInfoServer = server$(async (countryId: string) => {
const session = await getSession(server$.request, authOptions);
const user = await getAndVerifyUser(session);

return await prisma.country.findFirst({ where: { userId: user.id } });
});
I have tried upgrading to something like:
export const fetchCountryInfoServer = async (countryId: string) => {
"use server"
const session = await getSession(getWebRequest(), authOptions);
const user = await getAndVerifyUser(session);

return await prisma.country.findFirst({ where: { userId: user.id } });
};
export const fetchCountryInfoServer = async (countryId: string) => {
"use server"
const session = await getSession(getWebRequest(), authOptions);
const user = await getAndVerifyUser(session);

return await prisma.country.findFirst({ where: { userId: user.id } });
};
And this is just called in a button onClick() method on my frontend:
const onClick = async () => {
const expandedCountry = await fetchCountryInfoServer(country.id);
// Assign to store...
};
const onClick = async () => {
const expandedCountry = await fetchCountryInfoServer(country.id);
// Assign to store...
};
But the problem is that I get the following fairly generic error:
[auth][error] UnknownAction: Cannot parse action at /api/auth/session. Read more at https://errors.authjs.dev#unknownaction
[auth][error] UnknownAction: Cannot parse action at /api/auth/session. Read more at https://errors.authjs.dev#unknownaction
npm
@solid-mediakit/auth
An authentication utility library for Solid 2.. Latest version: 2.0.12, last published: 14 days ago. Start using @solid-mediakit/auth in your project by running npm i @solid-mediakit/auth. There are no other projects in the npm registry using @solid-mediakit/auth.
3 Replies
zimo
zimoOP•5mo ago
So I tried extracting the session to its own function to sanity check myself:
const getUser = async () => {
"use server"
console.log(1);
const request = getWebRequest();
console.log(2);
console.log(request);
console.log(3);
const session = await getSession(request, authOptions);
console.log(session);
console.log(4);
return session;
};
const getUser = async () => {
"use server"
console.log(1);
const request = getWebRequest();
console.log(2);
console.log(request);
console.log(3);
const session = await getSession(request, authOptions);
console.log(session);
console.log(4);
return session;
};
And it crashed between 3 and 4, i.e. on getSession(). This is all very confusing so I tried replicating it on a minimum working project. And there I kind of got it working, but I MUST use cache() and createAsync() exactly like in the example on: https://www.npmjs.com/package/@solid-mediakit/auth#server-side And even then I get the same error when I navigate from "Protected" to "Index" (or back and forth a few times). Here is the repo for the minimum project: https://github.com/zimonitrome/SolidStart-Prisma-AuthJS-example @OrJDev Sorry to bother you. Maybe you can help me out.
peerreynders
peerreynders•5mo ago
Just an FYI. Same error here: https://discord.com/channels/722131463138705510/1254011498632708147/1254091696342438029 Doesn't mean your issue is the same.
zimo
zimoOP•5mo ago
Haha thanks! Funnily enough I found the exact same fix just 10 minutes after your reply, but after an hour+ of digging 🙃 Nevertheless this finally fixed it! But it probably shouldn't need to. @OrJDev this could be worth looking into if you ever run out of work :) https://discord.com/channels/722131463138705510/1254011498632708147/1254172874663526440
Want results from more Discord servers?
Add your server