54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import type { NextAuthOptions } from "next-auth";
|
|
import GoogleProvider from "next-auth/providers/google";
|
|
import GitHubProvider from "next-auth/providers/github";
|
|
|
|
/**
|
|
* NextAuth options: Google & GitHub OAuth.
|
|
* Env: NEXTAUTH_SECRET veya NEXT_AUTH_SECRET, NEXTAUTH_URL,
|
|
* GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET,
|
|
* GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET
|
|
*/
|
|
const isProd = process.env.NODE_ENV === "production";
|
|
|
|
export const authOptions: NextAuthOptions = {
|
|
secret: process.env.NEXTAUTH_SECRET ?? process.env.NEXT_AUTH_SECRET,
|
|
useSecureCookies: isProd,
|
|
cookies: {
|
|
sessionToken: {
|
|
name: `${isProd ? "__Secure-" : ""}next-auth.session-token`,
|
|
options: {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
path: "/",
|
|
secure: isProd,
|
|
maxAge: 30 * 24 * 60 * 60, // 30 gün
|
|
},
|
|
},
|
|
},
|
|
providers: [
|
|
GoogleProvider({
|
|
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
|
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
|
|
}),
|
|
GitHubProvider({
|
|
clientId: process.env.GITHUB_CLIENT_ID ?? "",
|
|
clientSecret: process.env.GITHUB_CLIENT_SECRET ?? "",
|
|
authorization: {
|
|
params: {
|
|
scope: "user:email",
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
pages: {
|
|
signIn: "/auth/login",
|
|
},
|
|
callbacks: {
|
|
redirect({ url, baseUrl }) {
|
|
if (url.startsWith("/")) return `${baseUrl}${url}`;
|
|
if (new URL(url).origin === baseUrl) return url;
|
|
return baseUrl;
|
|
},
|
|
},
|
|
};
|