Tonymif
Tonymif
Explore posts from servers
BABetter Auth
Created by Tonymif on 4/12/2025 in #help
NextJS Build Fail with createAuthClient
I swapped the import { betterFetch } from 'better-auth/react'; to the import { betterFetch } from '@better-fetch/fetch';
8 replies
BABetter Auth
Created by Tonymif on 4/12/2025 in #help
NextJS Build Fail with createAuthClient
ok solved
8 replies
BABetter Auth
Created by Tonymif on 4/12/2025 in #help
NextJS Build Fail with createAuthClient
Either way, even this won't work:
import { NextMiddleware, NextResponse } from 'next/server';
import { betterFetch } from 'better-auth/react';
import { Session } from 'better-auth/types';

const nextMiddleware: NextMiddleware = async (request, event) => {
try {
const { data: session } = await betterFetch<Session>(
'/api/auth/get-session',
{
baseURL: 'http://localhost:3000',
headers: {
cookie: request.headers.get('cookie') || '',
Authorization: request.headers.get('Authorization') || '',
},
}
);

if (!session) {
return NextResponse.redirect(new URL("/", request.url));
}
} catch (error) {
console.error('Error in NextMiddleware', error);
}

return NextResponse.next();
};

export default nextMiddleware;

export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
import { NextMiddleware, NextResponse } from 'next/server';
import { betterFetch } from 'better-auth/react';
import { Session } from 'better-auth/types';

const nextMiddleware: NextMiddleware = async (request, event) => {
try {
const { data: session } = await betterFetch<Session>(
'/api/auth/get-session',
{
baseURL: 'http://localhost:3000',
headers: {
cookie: request.headers.get('cookie') || '',
Authorization: request.headers.get('Authorization') || '',
},
}
);

if (!session) {
return NextResponse.redirect(new URL("/", request.url));
}
} catch (error) {
console.error('Error in NextMiddleware', error);
}

return NextResponse.next();
};

export default nextMiddleware;

export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
.
8 replies