lonelyplanet
lonelyplanet
Explore posts from servers
BABetter Auth
Created by George on 3/14/2025 in #help
Payload Request shows email and Password
4 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
Can you try it maybe?
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
Edit you NEXTJS middleware
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
Your hono server is fine, its the nextjs application.
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
?
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
thats your nextjs middleware
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
why can you not do that
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
import { NextRequest, NextResponse } from "next/server";
import { client } from "./lib/client";
import { cookies } from 'next/headers'; // import nextjs cookies here

export const middleware = async (req: NextRequest) => {
const cookieString = (await cookies()).toString(); // get cookie string
const { userSession } = await (
await client.user.getUserSession.$get(undefined, {
headers: {
Cookie: cookieString,
},
})
).json();

//existing code...
}
import { NextRequest, NextResponse } from "next/server";
import { client } from "./lib/client";
import { cookies } from 'next/headers'; // import nextjs cookies here

export const middleware = async (req: NextRequest) => {
const cookieString = (await cookies()).toString(); // get cookie string
const { userSession } = await (
await client.user.getUserSession.$get(undefined, {
headers: {
Cookie: cookieString,
},
})
).json();

//existing code...
}
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
Why?
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
Your not listening. You need to PASS the cookies to your server
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
and then pass them to your server
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
You need to get cookies in nextjs middleware
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
what is
import { client } from "./lib/client"
import { client } from "./lib/client"
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
await client.user.getUserSession.$get(); // pass in the cookie header into this request
await client.user.getUserSession.$get(); // pass in the cookie header into this request
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
you would have to add the cookie header to the call your making with your client
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
that was with a fetch
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
import { cookies } from 'next/headers';

// Get cookie string representation
const cookieString = (await cookies()).toString();

// Use in fetch request
const response = await fetch('/my-url', {
headers: {
Cookie: cookieString
}
});
import { cookies } from 'next/headers';

// Get cookie string representation
const cookieString = (await cookies()).toString();

// Use in fetch request
const response = await fetch('/my-url', {
headers: {
Cookie: cookieString
}
});
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
you have to add the cookies header to the get request
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
The problem is when you run this on your browser await client.user.getUserSession.$get() -> the Browser is automatctially appending the cookies to the request However if called from the server cookies dont exist on the server so how is it supposed to send the cookies?
157 replies
BABetter Auth
Created by Sithu Khant on 2/17/2025 in #help
Hono and Better-Auth
is this ./lib/client?
157 replies