Skip to content

Commit

Permalink
chore: fix test types
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekacru committed Oct 27, 2024
1 parent a3d69b3 commit b36c03f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
26 changes: 16 additions & 10 deletions demo/nextjs/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { betterFetch } from "@better-fetch/fetch";
import { NextRequest, NextResponse } from "next/server";
import type { Session } from "./lib/auth-types";
import { client } from "./lib/auth-client";

export default async function authMiddleware(request: NextRequest) {
const { data: session } = await betterFetch<Session>(
"/api/auth/get-session",
{
baseURL: request.nextUrl.origin,
export async function middleware(request: NextRequest) {
// const { data: session } = await betterFetch<Session>(
// "/api/auth/get-session",
// {
// baseURL: request.nextUrl.origin,
// headers: {
// //get the cookie from the request
// cookie: request.headers.get("cookie") || "",
// },
// },
// );
const session = await client.getSession({
fetchOptions: {
headers: {
//get the cookie from the request
cookie: request.headers.get("cookie") || "",
},
},
);
});

if (!session) {
if (!session.data) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ describe("oauth2", async () => {
});

it("should handle server error during OAuth flow", async () => {
server.service.once("beforeUserinfo", (tokenResponse) => {
server.service.once("beforeUserinfo", (userInfoResponse) => {
userInfoResponse.body = {
email: "oauth2@test.com",
name: "OAuth2 Test",
sub: "oauth2",
picture: "https://test.com/picture.png",
email_verified: true,
};
userInfoResponse.statusCode = 500;
});
Expand Down

0 comments on commit b36c03f

Please sign in to comment.