35 lines
783 B
TypeScript
35 lines
783 B
TypeScript
import NextAuth from "next-auth";
|
|
import { authOptions } from "@/lib/auth";
|
|
|
|
const handler = NextAuth({
|
|
...authOptions,
|
|
debug: true, // Enable debug logging
|
|
callbacks: {
|
|
...authOptions.callbacks,
|
|
async redirect({ url, baseUrl }) {
|
|
console.log('Redirect callback:', { url, baseUrl });
|
|
// Allows relative callback URLs
|
|
if (url.startsWith("/")) return `${baseUrl}${url}`;
|
|
// Allows callback URLs on the same origin
|
|
else if (new URL(url).origin === baseUrl) return url;
|
|
return baseUrl;
|
|
}
|
|
},
|
|
});
|
|
|
|
export { handler as GET, handler as POST };
|
|
|
|
interface JWT {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
accessTokenExpires: number;
|
|
}
|
|
|
|
interface Profile {
|
|
sub?: string;
|
|
email?: string;
|
|
name?: string;
|
|
roles?: string[];
|
|
}
|
|
|