Skip to content

Commit

Permalink
remove solid auth
Browse files Browse the repository at this point in the history
  • Loading branch information
OrJDev committed Dec 28, 2022
1 parent ba9e72c commit 0af00ef
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 367 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ npm create jd-app@latest
- [Solid Start](https://github.com/solidjs/solid-start)
- [TypeScript](https://github.com/microsoft/TypeScript)
- [Zod](https://github.com/colinhacks/zod)
- [Solid EsLint](https://github.com/solidjs-community/eslint-plugin-solid)

## Addons

Expand All @@ -22,7 +23,6 @@ All addons are optional, you may select some, you may select all and you may sel
- [tRPC](https://github.com/trpc/trpc)
- [TailwindCSS](https://github.com/tailwindlabs/tailwindcss)
- [UnoCSS](https://github.com/unocss/unocss)
- [SolidAuth](https://github.com/orjdev/solid-auth)
- [Next Auth](https://github.com/orjdev/auth-solid)
- [Upstash Ratelimit](https://github.com/upstash/ratelimit)

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "create-jd-app",
"version": "1.0.113",
"version": "1.0.115",
"main": "dist/index.js",
"scripts": {
"test": "ts-node -r tsconfig-paths/register src",
"build": "rm -rf dist && tsc -p . && tsc-alias -p tsconfig.json",
"postbuild": "ts-node -r tsconfig-paths/register src/scripts/copyFiles",
"patch": "npm version patch --no-git-tag-version",
"cp": "ts-node -r tsconfig-paths/register src/scripts/copyFiles",
"dev": "npm link && cd dist && npm link create-jd-app"
},
"bin": {
Expand Down
14 changes: 6 additions & 8 deletions src/helpers/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { formatError } from "~utils/helpers";
import { vercelPackages, vercelEnv } from "~vercel";
import chalk from "chalk";
import { IExpectedPackages } from "./packages";
import { TInstallers } from "~types";

export default async (
ctx: ICtx
Expand Down Expand Up @@ -93,7 +94,7 @@ export async function getCtxWithInstallers(
curr: string[]
): Promise<ICtx> {
let installers: string[] = [];
let pkgs: string[] = [];
let pkgs: TInstallers[] = [];
const skip = curr.includes("skip");
try {
installers = await fs.readdir(path.join(__dirname, "../installers"));
Expand All @@ -113,10 +114,7 @@ export async function getCtxWithInstallers(
let optInstallers = installers.filter(
(pkg) => !validInstallers.includes(pkg)
);
const opts = [
["TailwindCSS", "UnoCSS"],
["SolidAuth", "NextAuth"],
];
const opts = [["TailwindCSS", "UnoCSS"]];
for (const opt of opts) {
for (const op of opt) {
if (validInstallers.includes(op)) {
Expand All @@ -125,7 +123,7 @@ export async function getCtxWithInstallers(
}
}
const newPkgs = (
await inquirer.prompt<{ pkgs: string[] }>({
await inquirer.prompt<{ pkgs: TInstallers[] }>({
name: "pkgs",
type: "checkbox",
message: "What should we use for this app?",
Expand All @@ -142,9 +140,9 @@ export async function getCtxWithInstallers(
},
})
).pkgs;
pkgs = [...validInstallers, ...newPkgs];
pkgs = [...validInstallers, ...newPkgs] as TInstallers[];
} else {
pkgs = validInstallers;
pkgs = validInstallers as TInstallers[];
}
}
if (pkgs.includes("Prisma") && !ctx.vercel) {
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const packages = {
"@trpc/server": "^10.1.0",
"solid-start-trpc": "^0.0.16",
"solid-trpc": "^0.0.11-rc.2",
// solid auth
"@solid-auth/core": "^0.0.1",
"@solid-auth/socials": "^0.0.2",
// next auth
"@solid-auth/next": "^0.0.19",
"@auth/core": "^0.1.4",
Expand Down
115 changes: 39 additions & 76 deletions src/helpers/utils/getIndexPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const getIndexPage: IUtil = (ctx) => {
const useStyles = useUno || uswTW;
const useTRPC = ctx.installers.includes("tRPC");
const useNextAuth = ctx.installers.includes("NextAuth");
const useSolidAuth = ctx.installers.includes("SolidAuth");
const useAuth = useNextAuth || useSolidAuth;
const shouldUsePrisma =
ctx.installers.includes("Prisma") && !useTRPC && !useAuth;
ctx.installers.includes("Prisma") && !useTRPC && !useNextAuth;
const withStyles = getStyle(
useStyles,
`font-bold text-2xl ${useUno ? "text-gray" : "text-gray-500"}`
Expand All @@ -22,43 +20,33 @@ const getIndexPage: IUtil = (ctx) => {
} mx-3 my-3 rounded-lg w-56 p-2.5 text-white font-bold flex items-center justify-center`
);

const loginKey = useSolidAuth ? "discord" : "github";
const innerRes = getRes(useNextAuth, useSolidAuth, shouldUsePrisma, useTRPC);
const innerRes = getRes(useNextAuth, shouldUsePrisma, useTRPC);
const innerContent = getContent(
withStyles,
useSolidAuth,
useNextAuth,
shouldUsePrisma,
loginKey,
useTRPC,
withButtonStyles
);
return `import { type VoidComponent${
useTRPC || shouldUsePrisma || useAuth ? ", Switch, Match" : ""
useTRPC || shouldUsePrisma || useNextAuth ? ", Switch, Match" : ""
}${shouldUsePrisma ? ", createResource" : ""} } from "solid-js";
import { Title${useAuth ? ", useRouteData" : ""} } from "solid-start";${
import { Title${useNextAuth ? ", useRouteData" : ""} } from "solid-start";${
useTRPC ? '\nimport { trpc } from "~/utils/trpc";' : ""
}${
useAuth ? `\nimport { createServerData$ } from "solid-start/server";` : ""
}${
useSolidAuth
? `\nimport { authenticator } from "~/server/auth";
import { authClient } from "~/utils/auth";`
useNextAuth
? `\nimport { createServerData$ } from "solid-start/server";`
: ""
}${
useNextAuth
? `\nimport { getSession } from "@solid-auth/next";\nimport { authOpts } from "./api/auth/[...solidauth]";\nimport { signIn, signOut } from "@solid-auth/next/client";`
: ""
}
${
useAuth
useNextAuth
? `\nexport const routeData = () => {
return createServerData$(async (_, { request }) => {
return await ${
useSolidAuth
? "authenticator.isAuthenticated(request)"
: "getSession(request, authOpts)"
};
return await getSession(request, authOpts);
});
};
`
Expand All @@ -83,22 +71,19 @@ export default getIndexPage;

const getRes = (
useNextAuth: boolean,
useSolidAuth: boolean,
shouldUsePrisma: boolean,
useTRPC: boolean
) => {
if ((useNextAuth || useSolidAuth) && useTRPC) {
return `\n const ${
useSolidAuth ? "user" : "session"
} = useRouteData<typeof routeData>();
if (useNextAuth && useTRPC) {
return `\n const session = useRouteData<typeof routeData>();
const res = trpc.secret.useQuery(undefined, {
get enabled() {
return ${useSolidAuth ? "!!user()" : "!!session()?.user"};
return !!session()?.user;
},
});
`;
}
if (useNextAuth || useSolidAuth) {
if (useNextAuth) {
return `\n const res = useRouteData<typeof routeData>();\n`;
}
return shouldUsePrisma
Expand All @@ -112,16 +97,12 @@ const getRes = (

const getContent = (
withStyles: string,
useSolidAuth: boolean,
useNextAuth: boolean,
shouldUsePrisma: boolean,
loginKey: string,
useTRPC: boolean,
withButtonStyles: string
) => {
const useAuth = useNextAuth || useSolidAuth;
const key = useSolidAuth ? "user" : "session";
if (useAuth && !useTRPC) {
if (useNextAuth && !useTRPC) {
return ` <Switch
fallback={
<div class="font-bold text-2xl text-gray-500">Loading...</div>
Expand All @@ -136,32 +117,23 @@ const getContent = (
<Switch
fallback={
<button
onClick={() => ${
useSolidAuth
? `authClient.login("${loginKey}", {
successRedirect: "/",
failureRedirect: "/",
})`
: `signIn("${loginKey}")`
}}${
withButtonStyles.length ? `\n ${withButtonStyles}` : ""
}
onClick={() => signIn("github")}${
withButtonStyles.length
? `\n ${withButtonStyles}`
: ""
}
>
Login with ${loginKey}
Login
</button>
}
>
<Match when={res()}>
<button
onClick={() => ${
useSolidAuth
? `authClient.logout({
redirectTo: "/",
})`
: "signOut()"
}}${
withButtonStyles.length ? `\n ${withButtonStyles}` : ""
}
onClick={() => signOut()}${
withButtonStyles.length
? `\n ${withButtonStyles}`
: ""
}
>
Logout
</button>
Expand All @@ -179,50 +151,41 @@ const getContent = (
withStyles.length ? "\n " : ""
}>
<Match when={res.${
shouldUsePrisma || (useAuth && !useTRPC) ? "loading" : "isLoading"
shouldUsePrisma || (useNextAuth && !useTRPC)
? "loading"
: "isLoading"
}}>
<div${withStyles}>${
useAuth && useTRPC && withStyles.length ? "\n" : ""
useNextAuth && useTRPC && withStyles.length ? "\n" : ""
}${
useAuth && useTRPC
useNextAuth && useTRPC
? ` {res.isFetching ? "Loading" : "Not Logged In"}`
: "Loading..."
}${useAuth && useTRPC ? "\n " : ""}</div>
}${useNextAuth && useTRPC ? "\n " : ""}</div>
</Match>
</Switch>${
useAuth && useTRPC
useNextAuth && useTRPC
? `\n <Switch
fallback={
<button
onClick={() => ${
useSolidAuth
? `authClient.login("${loginKey}", {
successRedirect: "/",
failureRedirect: "/",
})}`
: `signIn("${loginKey}")}`
}${
onClick={() => signIn("github")}
${
withButtonStyles.length
? `\n ${withButtonStyles}`
: ""
}
>
Login with ${loginKey}
Login
</button>
}
>
<Match when={${key}.loading}>
<h1>Loading ${key}</h1>
<Match when={session.loading}>
<h1>Loading session</h1>
</Match>
<Match when={${key}()}>
<Match when={session()}>
<button
onClick={() => ${
useSolidAuth
? `authClient.logout({
redirectTo: "/",
})}`
: "signOut()}"
}${
onClick={() => signOut()}
${
withButtonStyles.length
? `\n ${withButtonStyles}`
: ""
Expand Down
4 changes: 1 addition & 3 deletions src/installers/Prisma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const config: IInstaller = (ctx) => ({
path: `${__dirname}/files/client.txt`,
to: `${ctx.userDir}/src/server/db/client.ts`,
},
!ctx.installers.includes("tRPC") &&
!ctx.installers.includes("SolidAuth") &&
!ctx.installers.includes("NextAuth")
!ctx.installers.includes("tRPC") && !ctx.installers.includes("NextAuth")
? {
path: `${__dirname}/files/api.txt`,
to: `${ctx.userDir}/src/routes/api/notes.ts`,
Expand Down
7 changes: 0 additions & 7 deletions src/installers/Prisma/utils/getSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IUtil } from "~types";

const getSchema: IUtil = (ctx) => {
const useSolidAuth = ctx.installers.includes("SolidAuth");
const useNextAuth = ctx.installers.includes("NextAuth");
return `generator client {
provider = "prisma-client-js"
Expand Down Expand Up @@ -54,12 +53,6 @@ model VerificationToken {
token String @unique
expires DateTime
@@unique([identifier, token])
}`
: useSolidAuth
? `model User {
id String @id
displayName String
avatar String?
}`
: `model Notes {
id String @id @default(cuid())
Expand Down
8 changes: 0 additions & 8 deletions src/installers/SolidAuth/files/authUtils.txt

This file was deleted.

45 changes: 0 additions & 45 deletions src/installers/SolidAuth/files/prisma-server.txt

This file was deleted.

Loading

0 comments on commit 0af00ef

Please sign in to comment.