Omicrxn
Omicrxn
BABetter Auth
Created by gursh on 3/8/2025 in #help
Google oauth redirecting to /api/auth
Like supabase supabase.auth.exchangeCodeForSession('oauth code')
13 replies
BABetter Auth
Created by gursh on 3/8/2025 in #help
Google oauth redirecting to /api/auth
hey @KiNFiSH do you know if there is a way to exchange the code manually?
13 replies
BABetter Auth
Created by vijayatk3 on 4/17/2025 in #help
How to set Bearer token in Next.js
actually i was getting the same issue on sveltekit, and in the docs it says to put auth-client under lib/ so maybe it should be updated on the docs: https://www.better-auth.com/docs/integrations/svelte-kit#create-a-client
11 replies
BABetter Auth
Created by Omicrxn on 4/17/2025 in #help
Unclear on how to handle session and cookies in sveltekit
damm hate it when these silly mistakes take too long hahahah the life of a programmer, however it is not my scenario, I only have app/ route protected, api and others should be fine, thanks for the tip though, appreciate it!
8 replies
BABetter Auth
Created by Omicrxn on 4/17/2025 in #help
Unclear on how to handle session and cookies in sveltekit
i've been trying multiple methods, even using the client Auth but no luck the session is always null, in server and in client, using getSession, useSession it doesn't matter, the database does have an access token so i guess the auth is completing successfully. Any insights?
8 replies
BABetter Auth
Created by Omicrxn on 4/17/2025 in #help
Unclear on how to handle session and cookies in sveltekit
Thank you for the help in advanced!
8 replies
BABetter Auth
Created by Omicrxn on 4/17/2025 in #help
Unclear on how to handle session and cookies in sveltekit
i think this issue proposes something similar to what supabase does: https://github.com/better-auth/better-auth/issues/2020
8 replies
BABetter Auth
Created by Omicrxn on 4/17/2025 in #help
Unclear on how to handle session and cookies in sveltekit
After doing so my session is still null on all server side and also in the +hooks.svelte.ts where i do an Auth Guard which doesn't get triggered as the session is null. I've seen similar issues and the answer is saying to set the cookies manually as server getSession() doesn't do that but despite knowing how to do it with event.cookies.set it's unclear how to get the auth cookie from better auth. Also i think a great idea would be that better auth handles this internally, for instance supabase does this like this:
const supabase: Handle = async ({ event, resolve }) => {
event.locals.supabase = createServerClient(
PUBLIC_SUPABASE_URL,
PUBLIC_SUPABASE_ANON_KEY,
{
cookies: {
getAll: () => event.cookies.getAll(),
/**
* SvelteKit's cookies API requires `path` to be explicitly set in
* the cookie options. Setting `path` to `/` replicates previous/
* standard behavior.
*/
setAll: (cookiesToSet) => {
cookiesToSet.forEach(({ name, value, options }) => {
event.cookies.set(name, value, { ...options, path: "/" });
});
},
},
},
);

return resolve(event, {
filterSerializedResponseHeaders(name) {
/**
* Supabase libraries use the `content-range` and `x-supabase-api-version`
* headers, so we need to tell SvelteKit to pass it through.
*/
return name === "content-range" || name === "x-supabase-api-version";
},
});
};
const supabase: Handle = async ({ event, resolve }) => {
event.locals.supabase = createServerClient(
PUBLIC_SUPABASE_URL,
PUBLIC_SUPABASE_ANON_KEY,
{
cookies: {
getAll: () => event.cookies.getAll(),
/**
* SvelteKit's cookies API requires `path` to be explicitly set in
* the cookie options. Setting `path` to `/` replicates previous/
* standard behavior.
*/
setAll: (cookiesToSet) => {
cookiesToSet.forEach(({ name, value, options }) => {
event.cookies.set(name, value, { ...options, path: "/" });
});
},
},
},
);

return resolve(event, {
filterSerializedResponseHeaders(name) {
/**
* Supabase libraries use the `content-range` and `x-supabase-api-version`
* headers, so we need to tell SvelteKit to pass it through.
*/
return name === "content-range" || name === "x-supabase-api-version";
},
});
};
overall my request is that the sveltekit docs get updated to a real world scenario and also something that actually works similar to supabase docs where you can see how to handle typical files such as +hooks.server.ts +layout.ts etc https://supabase.com/docs/guides/auth/server-side/sveltekit and also to know how cookies must be handled in sveltekit server
8 replies