forked from t3-oss/create-t3-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextAuth.ts
34 lines (28 loc) · 1.15 KB
/
nextAuth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { type AvailableDependencies } from "~/installers/dependencyVersionMap.js";
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";
export const nextAuthInstaller: Installer = ({ projectDir, packages }) => {
const usingPrisma = packages?.prisma.inUse;
const deps: AvailableDependencies[] = ["next-auth"];
if (usingPrisma) deps.push("@next-auth/prisma-adapter");
addPackageDependency({
projectDir,
dependencies: deps,
devMode: false,
});
const extrasDir = path.join(PKG_ROOT, "template/extras");
const apiHandlerFile = "src/pages/api/auth/[...nextauth].ts";
const apiHandlerSrc = path.join(extrasDir, apiHandlerFile);
const apiHandlerDest = path.join(projectDir, apiHandlerFile);
const authConfigSrc = path.join(
extrasDir,
"src/server/auth",
usingPrisma ? "with-prisma.ts" : "base.ts",
);
const authConfigDest = path.join(projectDir, "src/server/auth.ts");
fs.copySync(apiHandlerSrc, apiHandlerDest);
fs.copySync(authConfigSrc, authConfigDest);
};