nope that works perfectly

nope that works perfectly
15 Replies
Varna
Varna•7mo ago
I mean the github oauth button but probs different problem from mine then
bun
bunOP•7mo ago
github oauth button works can you show me ur server action?
Varna
Varna•7mo ago
https://github.com/cloudflare/next-on-pages/issues/762
export async function mutationServerAction([input, duput]: [string, string?]) {
console.log("logging: mutationServerAction", input, duput);
revalidatePath("/");
return `mutation server action response: ${input}`;
}
export async function mutationServerAction([input, duput]: [string, string?]) {
console.log("logging: mutationServerAction", input, duput);
revalidatePath("/");
return `mutation server action response: ${input}`;
}
it doesn't even console log 😄
bun
bunOP•7mo ago
that works on local right?
Varna
Varna•7mo ago
yep everything works on local mutationServerAction fails on deployment if used on client, i.e. by calling via onClick
bun
bunOP•7mo ago
yeah weird af, we have very different scenarios but seems like a very similar bug
Varna
Varna•7mo ago
I guessed that Next updated smth (they had around 500 core changes for that version). And now next-on-pages fail to compile actions like that. another notice. It took me a while to make the reproduction. I added Clerk auth during that time. When I found the version bug, i started removing stuff. There still might be some stuff on browser end left, like cookies maybe? you said you were making smth with auth but this is just a wild guess now
bun
bunOP•7mo ago
im guessing it has something to do with redirect or revalidatePath (also has someting to do with redirect i assume) yup it was it basically, you cant use anything that redirects in a server action or it returns a 404
Varna
Varna•7mo ago
bad middleware maybe then? or smth similar cached away
bun
bunOP•7mo ago
Previous code:
export async function githubLogin() {
const { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } = getEnv();

const baseUrl = isDev() ? "http://localhost:3000" : "https://site.com";

const github = new GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, {
redirectURI: `${baseUrl}/auth/github/callback`,
});

const state = generateState();

cookies().set("state", state, {
httpOnly: true,
path: "/",
sameSite: "strict",
maxAge: 60 * 10, // 10 minutes
secure: !isDev(),
});

const url = await github.createAuthorizationURL(state, {
scopes: ["user:email"],
});

return redirect(url.toString());
}
export async function githubLogin() {
const { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } = getEnv();

const baseUrl = isDev() ? "http://localhost:3000" : "https://site.com";

const github = new GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, {
redirectURI: `${baseUrl}/auth/github/callback`,
});

const state = generateState();

cookies().set("state", state, {
httpOnly: true,
path: "/",
sameSite: "strict",
maxAge: 60 * 10, // 10 minutes
secure: !isDev(),
});

const url = await github.createAuthorizationURL(state, {
scopes: ["user:email"],
});

return redirect(url.toString());
}
Current code (that works): i changed the last part for return
const url = await github.createAuthorizationURL(state, {
scopes: ["user:email"],
});

return url.toString()
}
const url = await github.createAuthorizationURL(state, {
scopes: ["user:email"],
});

return url.toString()
}
then on client side i just navigate via window.location.href = url
Varna
Varna•7mo ago
I was using location.refresh() 😄 then changed to useRouter hook oh, I also had another strange thing. Instead of POSTing once. My deployment was making 2-8 requests instead. Some of which were instantly cancelled
bun
bunOP•7mo ago
client side navigation methodology doesnt really matter, the server side redirect fuxs things up, which im guessing what redirectPath does in some way you can just fix by awaiting the mutation function then calling router.refresh manually await mutationServerAction() router.refresh() and removing revalidatePath from the mutation function ofc thats strange but not sure what could've caused it without looking at the exact code
Varna
Varna•7mo ago
I meant, that after running mutation once on client, it made 1 request in browser, but logged 2-8 requests to POST handler of that mutation on CF tail which all returned 404s well, I already replaced action with an API server handler
bun
bunOP•7mo ago
how do you tail exactly?
Varna
Varna•7mo ago
I tried both CLI and CF Pages > Deployments > Funtions > start live stream
wrangler pages deployment tail --environment production --project-name support
wrangler pages deployment tail --environment production --project-name support
on Dashboard you can click each request for more details (in most cases) but it's pretty strange. If you log N times in same action. It ends up as an array of messages on single request. But in this case. It was empty for me. So the action didn't run at all, it was either not compiled, or had different url than client expected. I'm probably giving up on using Next with Pages. My VPS deployments feel more stable.
Want results from more Discord servers?
Add your server