Winston
Winston
Explore posts from servers
BABetter Auth
Created by Winston on 2/19/2025 in #help
What info does server getSession need?
Hi folks, I am trying to use Elysia with my Vite app. All the "provided" endpoints that pass through the basic middleware like sign in work:
async function betterAuthMiddleware(context: Context) {
return await auth.handler(context.request);
}
export const app = new Elysia({ prefix: "/api" })
.state(state)
.use(cors())
.all("/*", ({ request }) => {
console.log("request", request);
})
.all("/auth/*", betterAuthMiddleware)
async function betterAuthMiddleware(context: Context) {
return await auth.handler(context.request);
}
export const app = new Elysia({ prefix: "/api" })
.state(state)
.use(cors())
.all("/*", ({ request }) => {
console.log("request", request);
})
.all("/auth/*", betterAuthMiddleware)
Without using bearer token, is the below pattern possible, or does bearer need to be enabled?
// client
const serverClient = treaty<App>("http://localhost:7505", {
onRequest: async (_path, options) => {
const session = await authClient.getSession();
if (session.data?.session) {
return {
headers: {
...options.headers,
// IS THIS RIGHT? i'm starting to think no?
Authorization: `${session.data.session.token}`,
},
};
}
return options.headers;
},
});

// server
new Elysia()
.derive(async ({ request }) => {
const session = await auth.api.getSession({ headers: request.headers });
// session.data is always null/undefined here even with a valid auth token
if (!session || !session.user || !session.session) {
...
}
// client
const serverClient = treaty<App>("http://localhost:7505", {
onRequest: async (_path, options) => {
const session = await authClient.getSession();
if (session.data?.session) {
return {
headers: {
...options.headers,
// IS THIS RIGHT? i'm starting to think no?
Authorization: `${session.data.session.token}`,
},
};
}
return options.headers;
},
});

// server
new Elysia()
.derive(async ({ request }) => {
const session = await auth.api.getSession({ headers: request.headers });
// session.data is always null/undefined here even with a valid auth token
if (!session || !session.user || !session.session) {
...
}
If possible without bearer token, how do we call custom endpoints but sending session info? Config, for reference:
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
usePlural: true,
}),
secret: process.env.BETTER_AUTH_SECRET,
trustedOrigins: ["http://localhost:3001"],
emailAndPassword: {
enabled: true,
},
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async (
{ user, newEmail, url, token },
request,
) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);
},
},
},
plugins: [
organization({
...
}),
],
});
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
usePlural: true,
}),
secret: process.env.BETTER_AUTH_SECRET,
trustedOrigins: ["http://localhost:3001"],
emailAndPassword: {
enabled: true,
},
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async (
{ user, newEmail, url, token },
request,
) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);
},
},
},
plugins: [
organization({
...
}),
],
});
1 replies
CDCloudflare Developers
Created by Winston on 4/24/2024 in #general-help
How to use VS Code Debugger for Workers Rust?
I used the hello-world-rust template to start a Cloudflare Rust worker, but I am unable to use the VS Code debugger. In particular, I tried adding the config in the below tutorial, but the breakpoints in Rust files become unbound. How can I set up my VS Code to debug Rust? I have installed Rust analyzer and debugging works in other Rust projects. https://developers.cloudflare.com/workers/testing/debugging-tools
3 replies