Skip to content

Commit 8547036

Browse files
authored
feat(auth): Improve auth extras (#28)
Restructuring the auth output, and improving file structures.
2 parents 06d186a + 7c136b6 commit 8547036

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+383
-445
lines changed

.changeset/eleven-humans-smell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-sva": patch
3+
---
4+
5+
Improves oauth example with github email validation

.changeset/nervous-boats-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-sva": patch
3+
---
4+
5+
Add multi-file schema for drizzle

.changeset/rare-carrots-jam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-sva": patch
3+
---
4+
5+
Add missing verifier token required by some oauth providers

cli/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The _"SVA Stack"_ is a web development stack focused on **simplicity**, **consis
4040
| [Tailwind CSS](https://tailwindcss.com) | Styling | 💠 Recommended |
4141
| [Lucia](https://lucia-auth.com/) | Auth | 💠 Recommended |
4242
| [Drizzle](https://orm.drizzle.team/) | Database Adapter | 💠 Recommended |
43-
| [Husky](https://typicode.github.io/husky/) | Auth | 💠 Optional |
43+
| [Husky](https://typicode.github.io/husky/) | Git Hooks | 💠 Optional |
4444

4545
> [!NOTE]
4646
> create-sva is heavily inspired by the [t3stack](https://github.com/t3-oss/create-t3-app/), both in the methodology, and the CLI. The first version of this project used or learnt from many aspects of the t3 codebase, and we owe a lot to it's [contributors](https://github.com/t3-oss/create-t3-app/graphs/contributors).
@@ -83,7 +83,7 @@ The stated goal of `create-sva` is to provide the quickest way to start a new fu
8383

8484
<h2 id="getting-started">Getting Started</h2>
8585

86-
To scaffold an app using `create-t3-app`, run any of the following four commands and answer the command prompt questions:
86+
To scaffold an app using `create-sva`, run any of the following four commands and answer the command prompt questions:
8787

8888
### npm
8989

cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
],
3434
"scripts": {
3535
"typecheck": "tsc --noEmit",
36-
"build:css": "npx tailwind -i ./template/extras/src/tailwind.pcss -o ./template/base/src/app.pcss",
36+
"build:css": "npx tailwind -i ./template/extras/tailwind/app.pcss -o ./template/base/src/app.pcss",
3737
"build:readme": "cp -f ../README.md ./",
3838
"build": "tsup",
3939
"dev": "tsup --watch",
@@ -68,7 +68,7 @@
6868
"devDependencies": {
6969
"@types/fs-extra": "^11.0.4",
7070
"@types/gradient-string": "^1.1.6",
71-
"@types/node": "^20.14.9",
71+
"@types/node": "^20.14.10",
7272
"prettier": "^3.3.2",
7373
"prettier-plugin-svelte": "^3.2.5",
7474
"prettier-plugin-tailwindcss": "^0.6.5",
+19-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import { PKG_ROOT } from "$src/data/constants.js";
2+
import { AvailableDependencies } from "$src/installers/dependency-version-map.js";
23
import { type Installer } from "$src/installers/installer.js";
34
import { add_pkg_dependency } from "$src/utility/add-pkg-dependency.js";
45
import fs from "fs-extra";
56
import path from "path";
67

7-
export const adapter_auto_installer: Installer = ({ project_dir }) => {
8-
// Add dependencies to package json
8+
type AdapterType = "auto" | "cloudflare" | "netlify" | "node" | "vercel";
99

10-
add_pkg_dependency({
11-
project_dir,
12-
dependencies: ["@sveltejs/adapter-auto"],
13-
is_dev_dependency: true,
14-
});
10+
export const get_adapter_installer = (adapter: AdapterType): Installer => {
11+
const dependencies: AvailableDependencies[] = [`@sveltejs/adapter-${adapter}`];
1512

16-
// Moving Files
13+
const extras_dir = path.join(PKG_ROOT, "template/extras");
14+
const config_src = path.join(extras_dir, `config/svelte-${adapter}.js`);
1715

18-
// Move template svelte.config.js file
16+
const adapter_auto_installer: Installer = ({ project_dir }) => {
17+
// Add dependencies to package json
1918

20-
const extras_dir = path.join(PKG_ROOT, "template/extras");
19+
add_pkg_dependency({
20+
project_dir,
21+
dependencies,
22+
is_dev_dependency: true,
23+
});
24+
25+
// Moving Files
2126

22-
const config_src = path.join(extras_dir, `config/svelte-auto.js`);
23-
const config_dest = path.join(project_dir, "svelte.config.js");
27+
const config_dest = path.join(project_dir, "svelte.config.js");
28+
fs.copySync(config_src, config_dest);
29+
};
2430

25-
fs.copySync(config_src, config_dest);
31+
return adapter_auto_installer;
2632
};

cli/src/installers/installer.adapter-cloudflare.ts

-26
This file was deleted.

cli/src/installers/installer.adapter-netlify.ts

-26
This file was deleted.

cli/src/installers/installer.adapter-node.ts

-26
This file was deleted.

cli/src/installers/installer.adapter-vercel.ts

-26
This file was deleted.

cli/src/installers/installer.drizzle.ts

+25-21
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,41 @@ export const drizzle_installer: Installer = ({ packages, project_dir, database_s
5757

5858
// Moving Files
5959

60-
const source = path.join(PKG_ROOT, "template/extras");
61-
const dest_server = path.join(project_dir, "src/lib/server");
60+
const template_dir = path.join(PKG_ROOT, "template/extras/drizzle");
61+
const db_dir = path.join(project_dir, "src/lib/server/db");
62+
fs.mkdirSync(db_dir, { recursive: true });
6263

6364
// Setup config files
6465

65-
const config_src = path.join(source, `config/drizzle-config-${database_solution}.ts`);
66+
const config_src = path.join(template_dir, `drizzle.config-${database_solution}.ts`);
6667
const config_dest = path.join(project_dir, "drizzle.config.ts");
67-
const config_content = fs.readFileSync(config_src, "utf-8");
68+
fs.copySync(config_src, config_dest, { overwrite: true });
6869

6970
// Setup schema files
7071

71-
const schema_suffix = packages?.["lucia"].is_used ? "-lucia" : "";
72-
const schema_src = path.join(
73-
source,
74-
`src/lib/server/schema-${database_solution}${schema_suffix}.ts`,
75-
);
76-
const schema_dest = path.join(dest_server, "schema.ts");
77-
const schema_content = fs.readFileSync(schema_src, "utf-8");
72+
if (packages?.["lucia"].is_used) {
73+
const schema_lucia_src = path.join(template_dir, `lib/schema-${database_solution}-lucia.ts`);
74+
const schema_lucia_dest = path.join(db_dir, "schema.lucia.ts");
75+
fs.copySync(schema_lucia_src, schema_lucia_dest, { overwrite: true });
76+
77+
const schema_src = path.join(template_dir, `lib/schema-lucia.ts`);
78+
const schema_dest = path.join(db_dir, "schema.ts");
79+
fs.copySync(schema_src, schema_dest, { overwrite: true });
80+
} else {
81+
const schema_demo_src = path.join(template_dir, `lib/schema-${database_solution}-demo.ts`);
82+
const schema_demo_dest = path.join(db_dir, "schema.demo.ts");
83+
fs.copySync(schema_demo_src, schema_demo_dest, { overwrite: true });
84+
85+
const schema_src = path.join(template_dir, `lib/schema-demo.ts`);
86+
const schema_dest = path.join(db_dir, "schema.ts");
87+
fs.copySync(schema_src, schema_dest, { overwrite: true });
88+
}
7889

7990
// Setup client files
8091

81-
const client_src = path.join(source, `src/lib/server/db-${database_solution}.ts`);
82-
const client_dest = path.join(dest_server, "db.ts");
92+
const client_src = path.join(template_dir, `lib/db-${database_solution}.ts`);
93+
const client_dest = path.join(db_dir, "index.ts");
94+
fs.copySync(client_src, client_dest, { overwrite: true });
8395

8496
// Add db:* scripts to package.json
8597
update_pkg_json({
@@ -95,12 +107,4 @@ export const drizzle_installer: Installer = ({ packages, project_dir, database_s
95107
return pkg;
96108
},
97109
});
98-
99-
// Write files to project directory
100-
101-
fs.copySync(config_src, config_dest, { overwrite: true });
102-
fs.mkdirSync(path.dirname(schema_dest), { recursive: true });
103-
fs.writeFileSync(schema_dest, schema_content);
104-
fs.writeFileSync(config_dest, config_content);
105-
fs.copySync(client_src, client_dest, { overwrite: true });
106110
};

cli/src/installers/installer.lucia.ts

+42-42
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,62 @@ export const lucia_installer: Installer = ({ project_dir, database_solution }) =
2424

2525
// Moving Files
2626

27-
const source = path.join(PKG_ROOT, "template/extras");
28-
const dest = path.join(project_dir, "src/");
27+
const template_dir = path.join(PKG_ROOT, "template/extras/lucia");
28+
const routes_dir = path.join(project_dir, "src/routes");
29+
const auth_dir = path.join(project_dir, "src/lib/server/auth");
30+
fs.mkdirSync(auth_dir, { recursive: true });
2931

30-
// Lib
31-
32-
const global_types_src = path.join(source, `src/app-lucia.ts`);
33-
const global_types_dest = path.join(dest, "app.d.ts");
34-
35-
const hook_server_src = path.join(source, `src/hooks-server-lucia.ts`);
36-
const hook_server_dest = path.join(dest, "hooks.server.ts");
37-
38-
const auth_src = path.join(source, `src/lib/server/lucia-${database_solution}.ts`);
39-
const auth_dest = path.join(dest, "lib/server/auth.ts");
40-
41-
const auth_create_session_src = path.join(source, `src/lib/server/lucia-auth.create-session.ts`);
42-
const auth_create_session_dest = path.join(dest, "lib/server/auth.create-session.ts");
43-
44-
const auth_oauth_provider_src = path.join(source, `src/lib/server/lucia-auth.oauth-provider.ts`);
45-
const auth_oauth_provider_dest = path.join(dest, "lib/server/auth.oauth-provider.ts");
46-
47-
const auth_use_oauth_src = path.join(source, `src/lib/server/lucia-auth.use-oauth.ts`);
48-
const auth_use_oauth_dest = path.join(dest, "lib/server/auth.use-oauth.ts");
32+
// Framework
4933

50-
/* Routes */
51-
52-
const account_server_src = path.join(source, `src/routes/lucia/page-account.ts`);
53-
const account_server_dest = path.join(dest, "routes/account/+page.server.ts");
54-
55-
const account_svelte_src = path.join(source, `src/routes/lucia/page-account.svelte`);
56-
const account_svelte_dest = path.join(dest, "routes/account/+page.svelte");
57-
58-
const login_server_src = path.join(source, `src/routes/lucia/page-login.ts`);
59-
const login_server_dest = path.join(dest, "routes/login/+page.server.ts");
60-
61-
const login_svelte_src = path.join(source, `src/routes/lucia/page-login.svelte`);
62-
const login_svelte_dest = path.join(dest, "routes/login/+page.svelte");
34+
const global_types_src = path.join(template_dir, `app.d.ts`);
35+
const global_types_dest = path.join(project_dir, "src/app.d.ts");
36+
fs.copySync(global_types_src, global_types_dest, { overwrite: true });
6337

64-
const login_gh_server_src = path.join(source, `src/routes/lucia/github-login.ts`);
65-
const login_gh_server_dest = path.join(dest, "routes/login/github/+server.ts");
38+
const hook_server_src = path.join(template_dir, `hooks.server.ts`);
39+
const hook_server_dest = path.join(project_dir, "src/hooks.server.ts");
40+
fs.copySync(hook_server_src, hook_server_dest, { overwrite: true });
6641

67-
const login_ghcb_server_src = path.join(source, `src/routes/lucia/github-callback.ts`);
68-
const login_ghcb_server_dest = path.join(dest, "routes/login/github/callback/+server.ts");
42+
// Lib
6943

70-
// Copy Lib
71-
fs.copySync(global_types_src, global_types_dest, { overwrite: true });
72-
fs.copySync(hook_server_src, hook_server_dest, { overwrite: true });
44+
const auth_src = path.join(template_dir, `lib/with-${database_solution}.ts`);
45+
const auth_dest = path.join(auth_dir, "index.ts");
7346
fs.copySync(auth_src, auth_dest, { overwrite: true });
47+
48+
const auth_create_session_src = path.join(template_dir, `lib/create-session.ts`);
49+
const auth_create_session_dest = path.join(auth_dir, "create-session.ts");
7450
fs.copySync(auth_create_session_src, auth_create_session_dest, { overwrite: true });
51+
52+
const auth_oauth_provider_src = path.join(template_dir, `lib/oauth.ts`);
53+
const auth_oauth_provider_dest = path.join(auth_dir, "oauth.ts");
7554
fs.copySync(auth_oauth_provider_src, auth_oauth_provider_dest, { overwrite: true });
55+
56+
const auth_use_oauth_src = path.join(template_dir, `lib/use-oauth.ts`);
57+
const auth_use_oauth_dest = path.join(auth_dir, "use-oauth.ts");
7658
fs.copySync(auth_use_oauth_src, auth_use_oauth_dest, { overwrite: true });
7759

78-
// Copy Routes
60+
// Routes
61+
62+
const account_server_src = path.join(template_dir, `routes/account/+page.server.ts`);
63+
const account_server_dest = path.join(routes_dir, "account/+page.server.ts");
7964
fs.copySync(account_server_src, account_server_dest, { overwrite: true });
65+
66+
const account_svelte_src = path.join(template_dir, `routes/account/+page.svelte`);
67+
const account_svelte_dest = path.join(routes_dir, "account/+page.svelte");
8068
fs.copySync(account_svelte_src, account_svelte_dest, { overwrite: true });
69+
70+
const login_server_src = path.join(template_dir, `routes/login/+page.server.ts`);
71+
const login_server_dest = path.join(routes_dir, "login/+page.server.ts");
8172
fs.copySync(login_server_src, login_server_dest, { overwrite: true });
73+
74+
const login_svelte_src = path.join(template_dir, `routes/login/+page.svelte`);
75+
const login_svelte_dest = path.join(routes_dir, "login/+page.svelte");
8276
fs.copySync(login_svelte_src, login_svelte_dest, { overwrite: true });
77+
78+
const login_gh_server_src = path.join(template_dir, `routes/login/github/+server.ts`);
79+
const login_gh_server_dest = path.join(routes_dir, "login/github/+server.ts");
8380
fs.copySync(login_gh_server_src, login_gh_server_dest, { overwrite: true });
81+
82+
const login_ghcb_server_src = path.join(template_dir, `routes/login/github/callback/+server.ts`);
83+
const login_ghcb_server_dest = path.join(routes_dir, "login/github/callback/+server.ts");
8484
fs.copySync(login_ghcb_server_src, login_ghcb_server_dest, { overwrite: true });
8585
};

0 commit comments

Comments
 (0)