-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
2,133 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-t3-app": minor | ||
--- | ||
|
||
feat: add lucia auth option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import path from "path"; | ||
import fs from "fs-extra"; | ||
|
||
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 luciaInstaller: Installer = ({ | ||
projectDir, | ||
packages, | ||
appRouter, | ||
}) => { | ||
const usingPrisma = packages?.prisma.inUse; | ||
const usingDrizzle = packages?.drizzle.inUse; | ||
const usingTrpc = packages?.trpc.inUse; | ||
|
||
const deps: AvailableDependencies[] = ["lucia", "@lucia-auth/oauth"]; | ||
if (usingPrisma) deps.push("@lucia-auth/adapter-prisma"); | ||
if (usingDrizzle) deps.push("@lucia-auth/adapter-mysql"); | ||
|
||
addPackageDependency({ | ||
projectDir, | ||
dependencies: deps, | ||
devMode: false, | ||
}); | ||
|
||
const extrasDir = path.join(PKG_ROOT, "template/extras"); | ||
|
||
const tsDefinitionFile = "lucia-auth.d.ts"; | ||
|
||
const signInFile = appRouter | ||
? "src/app/api/auth/discord/signin/route.ts" | ||
: "src/pages/api/auth/discord/signin.ts"; | ||
const callbackFile = appRouter | ||
? "src/app/api/auth/discord/callback/route.ts" | ||
: "src/app/api/auth/discord/callback.ts"; | ||
const logOutFile = appRouter | ||
? "src/app/api/auth/logout/route.ts" | ||
: "src/pages/api/auth/logout.ts"; | ||
|
||
const signInSrc = path.join(extrasDir, signInFile); | ||
const signInDest = path.join(projectDir, signInFile); | ||
const callbackSrc = path.join(extrasDir, callbackFile); | ||
const callbackDest = path.join(projectDir, callbackFile); | ||
|
||
const tsDefinitionSrc = path.join(extrasDir, tsDefinitionFile); | ||
const tsDefinitionDest = path.join(projectDir, tsDefinitionFile); | ||
|
||
const authConfigSrc = path.join( | ||
extrasDir, | ||
"src/server", | ||
appRouter ? "lucia-app" : "lucia-pages", | ||
usingPrisma | ||
? "with-prisma.ts" | ||
: usingDrizzle | ||
? "with-drizzle.ts" | ||
: "base.ts" | ||
); | ||
const authConfigDest = path.join(projectDir, "src/server/auth.ts"); | ||
|
||
const copySrcDest: [string, string][] = [ | ||
[signInSrc, signInDest], | ||
[callbackSrc, callbackDest], | ||
[tsDefinitionSrc, tsDefinitionDest], | ||
[authConfigSrc, authConfigDest], | ||
]; | ||
|
||
if (appRouter) { | ||
copySrcDest.push([ | ||
path.join( | ||
extrasDir, | ||
usingTrpc | ||
? "src/app/_components/logout-button-trpc.tsx" | ||
: "src/app/_components/logout-button.tsx" | ||
), | ||
path.join(projectDir, "src/app/_components/logout-button.tsx"), | ||
]); | ||
} | ||
|
||
if (!usingTrpc) { | ||
const logOutSrc = path.join(extrasDir, logOutFile); | ||
const logOutDest = path.join(projectDir, logOutFile); | ||
|
||
copySrcDest.push([logOutSrc, logOutDest]); | ||
} | ||
|
||
copySrcDest.forEach(([src, dest]) => { | ||
fs.copySync(src, dest); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.