-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locals are always empty #10
Comments
I'm facing the same problem, have you been able to resolve it? |
I could solve it, it's stupid though as I don't understand what's the problem, I first applied the same check in |
Hey @knavels - I never did get it resolved now and I am a little disappointed that it was never addressed here or in the discord server when asking for help. Paid for a course, I kind of expected it to at least be supported. |
@knavels I am revisting this for another project and running into empty locals again, do you happen to have code snippet you could share? |
@damiensedgwick, sure dude, as I've mentioned I've renamed the
import type { PageServerLoad } from "./$types";
import { adminDB } from "$lib/server/admin";
import { error, redirect } from "@sveltejs/kit";
export const load: PageServerLoad = async ({ locals, params }) => {
const uid = locals.userID;
if (!uid) {
throw redirect(301, "/login");
}
const userDoc = await adminDB.collection("users").doc(uid!).get();
const { username } = userDoc.data()!;
if (params.username !== username) {
throw error(401, "That username does not belong to you");
}
return {};
};
import type { PageServerLoad, Actions } from "./$types";
import { adminDB } from "$lib/server/admin";
import { error, fail, redirect } from "@sveltejs/kit";
export const load: PageServerLoad = async ({ locals, params }) => {
const uid = locals.userID;
if (!uid) {
throw redirect(301, "/login");
}
const userDoc = await adminDB.collection("users").doc(uid!).get();
const { username, bio } = userDoc.data()!;
if (params.username !== username) {
throw error(401, "That username does not belong to you");
}
return {
bio,
};
};
export const actions = {
default: async ({ locals, request, params }) => {
const uid = locals.userID;
const data = await request.formData();
const bio = data.get('bio') as string;
const userRef = adminDB.collection("users").doc(uid!);
const { username } = (await userRef.get()).data()!;
if (params.username !== username) {
throw error(401, "That username does not belong to you");
}
if (bio!.length > 260) {
return fail(400, { problem: "Bio must be less than 260 characters" });
}
await userRef.update({
bio,
});
},
} satisfies Actions;
import { adminAuth } from "$lib/server/admin";
import type { Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
const sessionCookie = event.cookies.get("__session");
try {
const decodedClaims = await adminAuth.verifySessionCookie(sessionCookie!);
event.locals.userID = decodedClaims.uid;
console.log("found user id", event.locals);
} catch (e) {
event.locals.userID = null;
return resolve(event);
}
return resolve(event);
}; and at last the sveltekit version ^2.0.0 which I don't think that might be the case. |
Thanks a bunch @knavels I'll give this another go and maybe have a little more luck this time! Such a weird issue to be having! |
for some reason the word bio is cursed and doesn't work. if you rename the folder to something other than bio everything works as expected |
When trying to implement the server auth using the firebase admin sdk, locals are always empty. I cloned this repo down and used all of the code within this repo to test it to make sure it wasn't something i was doing and it was still broken.
Whenever I tried navigating to
user/bio
it would redirect to/login
The text was updated successfully, but these errors were encountered: