@batijs/cli 0.0.243 → 0.0.245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boilerplates/@batijs/authjs/files/$package.json.js +92 -0
- package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +14 -13
- package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +4 -2
- package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/compiled/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +8 -8
- package/dist/boilerplates/@batijs/drizzle/files/database/{db.ts → drizzleDb.ts} +1 -2
- package/dist/boilerplates/@batijs/drizzle/files/database/seed.ts +4 -3
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +1 -1
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzleDb.d.ts +1 -0
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/express/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +31 -9
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +6 -6
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +33 -45
- package/dist/boilerplates/@batijs/fastify/types/fastify-entry.d.ts +0 -4
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +5 -4
- package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +16 -18
- package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +8 -3
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +5 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +33 -24
- package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +0 -4
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +5 -3
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +33 -24
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +7 -15
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +31 -9
- package/dist/boilerplates/@batijs/lucia-auth/files/$.env.js +23 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$README.md.js +29 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +135 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/auth-actions.ts +54 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/schema/auth.ts +41 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/sqliteDb.ts +30 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +96 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/pages/login/+guard.ts +11 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/pages/login/style.css +94 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +340 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/vike.d.ts +11 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/auth-actions.d.ts +9 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/schema/auth.d.ts +167 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/sqliteDb.d.ts +2 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +43 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/pages/login/+guard.d.ts +3 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +58 -0
- package/dist/boilerplates/@batijs/react/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/react/files/layouts/LayoutDefault.tsx +1 -0
- package/dist/boilerplates/@batijs/react/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +96 -0
- package/dist/boilerplates/@batijs/react-lucia-auth/types/pages/login/+Page.d.ts +2 -0
- package/dist/boilerplates/@batijs/shared/files/package.json +2 -2
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +103 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +6 -8
- package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +3 -5
- package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/shared-server/types/server/vike-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +3 -3
- package/dist/boilerplates/@batijs/solid/files/$package.json.js +5 -5
- package/dist/boilerplates/@batijs/solid/files/layouts/LayoutDefault.tsx +1 -0
- package/dist/boilerplates/@batijs/solid/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +96 -0
- package/dist/boilerplates/@batijs/solid-lucia-auth/types/pages/login/+Page.d.ts +2 -0
- package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +3 -3
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +3 -3
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +3 -5
- package/dist/boilerplates/@batijs/telefunc/types/server/telefunc-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +3 -3
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +6 -9
- package/dist/boilerplates/@batijs/ts-rest/types/server/ts-rest-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/vercel/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/vue/files/$package.json.js +7 -7
- package/dist/boilerplates/@batijs/vue/files/layouts/LayoutDefault.vue +2 -0
- package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/vue/types/pages/+config.d.ts +6 -0
- package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +87 -0
- package/dist/boilerplates/boilerplates.json +59 -0
- package/dist/{chunk-MFJ4ET44.js → chunk-FWD3UPBV.js} +5 -5
- package/dist/index.js +14 -14
- package/dist/{prompt-SUR66HP4.js → prompt-EYFUFJSI.js} +4 -4
- package/package.json +8 -8
- package/dist/boilerplates/@batijs/drizzle/types/database/db.d.ts +0 -2
- /package/dist/boilerplates/@batijs/drizzle/files/database/{schema.ts → schema/todos.ts} +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{schema.d.ts → schema/todos.d.ts} +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// package.json
|
|
28
|
+
var require_package = __commonJS({
|
|
29
|
+
"package.json"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
name: "@batijs/lucia-auth",
|
|
32
|
+
private: true,
|
|
33
|
+
version: "0.0.1",
|
|
34
|
+
description: "",
|
|
35
|
+
type: "module",
|
|
36
|
+
scripts: {
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
build: "bati-compile-boilerplate"
|
|
39
|
+
},
|
|
40
|
+
keywords: [],
|
|
41
|
+
author: "",
|
|
42
|
+
license: "MIT",
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@batijs/drizzle": "workspace:*",
|
|
46
|
+
"@lucia-auth/adapter-drizzle": "^1.1.0",
|
|
47
|
+
"@lucia-auth/adapter-sqlite": "^3.0.2",
|
|
48
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
49
|
+
"@types/cookie": "^0.6.0",
|
|
50
|
+
"@types/node": "^18.19.14",
|
|
51
|
+
"@universal-middleware/core": "^0.2.3",
|
|
52
|
+
arctic: "^1.9.2",
|
|
53
|
+
"better-sqlite3": "^11.1.2",
|
|
54
|
+
cookie: "^0.6.0",
|
|
55
|
+
dotenv: "^16.4.5",
|
|
56
|
+
"drizzle-orm": "^0.33.0",
|
|
57
|
+
lucia: "^3.2.0",
|
|
58
|
+
vike: "^0.4.187",
|
|
59
|
+
vite: "^5.4.1"
|
|
60
|
+
},
|
|
61
|
+
dependencies: {
|
|
62
|
+
"@batijs/core": "workspace:*"
|
|
63
|
+
},
|
|
64
|
+
files: [
|
|
65
|
+
"dist/"
|
|
66
|
+
],
|
|
67
|
+
bati: {
|
|
68
|
+
if: {
|
|
69
|
+
flag: "lucia-auth"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
exports: {
|
|
73
|
+
"./database/sqliteDb": {
|
|
74
|
+
types: "./dist/types/database/sqliteDb.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./database/schema/auth": {
|
|
77
|
+
types: "./dist/types/database/schema/auth.d.ts"
|
|
78
|
+
},
|
|
79
|
+
"./database/auth-actions": {
|
|
80
|
+
types: "./dist/types/database/auth-actions.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./lib/lucia-auth": {
|
|
83
|
+
types: "./dist/types/lib/lucia-auth.d.ts"
|
|
84
|
+
},
|
|
85
|
+
"./pages/login/+guard": {
|
|
86
|
+
types: "./dist/types/pages/login/+guard.d.ts"
|
|
87
|
+
},
|
|
88
|
+
"./server/lucia-auth-handlers": {
|
|
89
|
+
types: "./dist/types/server/lucia-auth-handlers.d.ts"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
typesVersions: {
|
|
93
|
+
"*": {
|
|
94
|
+
"database/sqliteDb": [
|
|
95
|
+
"./dist/types/database/sqliteDb.d.ts"
|
|
96
|
+
],
|
|
97
|
+
"database/schema/auth": [
|
|
98
|
+
"./dist/types/database/schema/auth.d.ts"
|
|
99
|
+
],
|
|
100
|
+
"database/auth-actions": [
|
|
101
|
+
"./dist/types/database/auth-actions.d.ts"
|
|
102
|
+
],
|
|
103
|
+
"lib/lucia-auth": [
|
|
104
|
+
"./dist/types/lib/lucia-auth.d.ts"
|
|
105
|
+
],
|
|
106
|
+
"pages/login/+guard": [
|
|
107
|
+
"./dist/types/pages/login/+guard.d.ts"
|
|
108
|
+
],
|
|
109
|
+
"server/lucia-auth-handlers": [
|
|
110
|
+
"./dist/types/server/lucia-auth-handlers.d.ts"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// files/$package.json.ts
|
|
119
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
120
|
+
async function getPackageJson(props) {
|
|
121
|
+
const packageJson = await loadAsJson(props);
|
|
122
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
123
|
+
devDependencies: ["dotenv", "@types/better-sqlite3", "@types/cookie"],
|
|
124
|
+
dependencies: [
|
|
125
|
+
"arctic",
|
|
126
|
+
"cookie",
|
|
127
|
+
"lucia",
|
|
128
|
+
"@universal-middleware/core",
|
|
129
|
+
...props.meta.BATI.has("drizzle") ? ["@lucia-auth/adapter-drizzle"] : ["better-sqlite3", "@lucia-auth/adapter-sqlite"]
|
|
130
|
+
]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
getPackageJson as default
|
|
135
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
2
|
+
import { sqliteDb } from "./sqliteDb";
|
|
3
|
+
import { userTable, oauthAccountTable } from "./schema/auth";
|
|
4
|
+
import { eq, and } from "drizzle-orm";
|
|
5
|
+
|
|
6
|
+
export function getExistingUser(username: string) {
|
|
7
|
+
if (BATI.has("drizzle")) {
|
|
8
|
+
return drizzleDb.select().from(userTable).where(eq(userTable.username, username)).get();
|
|
9
|
+
} else {
|
|
10
|
+
return sqliteDb.prepare("SELECT * FROM users WHERE username = ?").get(username);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
15
|
+
if (BATI.has("drizzle")) {
|
|
16
|
+
return drizzleDb
|
|
17
|
+
.select()
|
|
18
|
+
.from(oauthAccountTable)
|
|
19
|
+
.where(and(eq(oauthAccountTable.providerId, providerId), eq(oauthAccountTable.providerUserId, providerUserId)))
|
|
20
|
+
.get();
|
|
21
|
+
} else {
|
|
22
|
+
return sqliteDb
|
|
23
|
+
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
24
|
+
.get(providerId, providerUserId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateInput(username: string | null, password: string | null) {
|
|
29
|
+
const error: {
|
|
30
|
+
username: string | null;
|
|
31
|
+
password: string | null;
|
|
32
|
+
} = {
|
|
33
|
+
username: null,
|
|
34
|
+
password: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (!username || username.length < 3 || username.length > 31 || !/^[a-z0-9_-]+$/.test(username)) {
|
|
38
|
+
error.username = "Invalid username";
|
|
39
|
+
}
|
|
40
|
+
if (!password || password.length < 6 || password.length > 255) {
|
|
41
|
+
error.password = "Invalid password";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (error.username || error.password) {
|
|
45
|
+
return {
|
|
46
|
+
error,
|
|
47
|
+
success: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
error,
|
|
52
|
+
success: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import { integer, primaryKey, sqliteTable, text, int } from "drizzle-orm/sqlite-core";
|
|
3
|
+
|
|
4
|
+
export const userTable = sqliteTable("users", {
|
|
5
|
+
id: text("id").notNull().primaryKey(),
|
|
6
|
+
username: text("username").notNull().unique(),
|
|
7
|
+
password: text("password"),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const oauthAccountTable = sqliteTable(
|
|
11
|
+
"oauth_accounts",
|
|
12
|
+
{
|
|
13
|
+
providerId: text("provider_id").notNull(),
|
|
14
|
+
providerUserId: int("provider_user_id").notNull(),
|
|
15
|
+
userId: text("user_id")
|
|
16
|
+
.notNull()
|
|
17
|
+
.references(() => userTable.id, {
|
|
18
|
+
onUpdate: "cascade",
|
|
19
|
+
onDelete: "cascade",
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
(table) => {
|
|
23
|
+
return {
|
|
24
|
+
pk: primaryKey({ columns: [table.providerId, table.providerUserId] }),
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const sessionTable = sqliteTable("sessions", {
|
|
30
|
+
id: text("id").notNull().primaryKey(),
|
|
31
|
+
userId: text("user_id")
|
|
32
|
+
.notNull()
|
|
33
|
+
.references(() => userTable.id, {
|
|
34
|
+
onUpdate: "cascade",
|
|
35
|
+
onDelete: "cascade",
|
|
36
|
+
}),
|
|
37
|
+
expiresAt: integer("expires_at").notNull(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export type UserItem = typeof userTable.$inferSelect;
|
|
41
|
+
export type UserInsert = typeof userTable.$inferInsert;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import sqlite, { type Database } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
export const sqliteDb: Database = sqlite(":memory:");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SQLite Schema
|
|
8
|
+
*
|
|
9
|
+
* @link {@see https://lucia-auth.com/database/sqlite#schema}
|
|
10
|
+
*/
|
|
11
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS users (
|
|
12
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
13
|
+
username TEXT NOT NULL UNIQUE,
|
|
14
|
+
password TEXT
|
|
15
|
+
)`);
|
|
16
|
+
|
|
17
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
18
|
+
provider_id TEXT NOT NULL,
|
|
19
|
+
provider_user_id INTEGER NOT NULL,
|
|
20
|
+
user_id TEXT NOT NULL,
|
|
21
|
+
PRIMARY KEY (provider_id, provider_user_id),
|
|
22
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
23
|
+
)`);
|
|
24
|
+
|
|
25
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
26
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
27
|
+
expires_at INTEGER NOT NULL,
|
|
28
|
+
user_id TEXT NOT NULL,
|
|
29
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
30
|
+
)`);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Lucia } from "lucia";
|
|
3
|
+
import { BetterSqlite3Adapter } from "@lucia-auth/adapter-sqlite";
|
|
4
|
+
import { GitHub } from "arctic";
|
|
5
|
+
import { sqliteDb } from "../database/sqliteDb";
|
|
6
|
+
import { DrizzleSQLiteAdapter } from "@lucia-auth/adapter-drizzle";
|
|
7
|
+
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
8
|
+
import { sessionTable, userTable } from "../database/schema/auth";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Polyfill needed if you're using Node.js 18 or below
|
|
12
|
+
*
|
|
13
|
+
* @link {@see https://lucia-auth.com/getting-started/#polyfill}
|
|
14
|
+
*/
|
|
15
|
+
if (!globalThis.crypto) {
|
|
16
|
+
Object.defineProperty(globalThis, "crypto", {
|
|
17
|
+
value: await import("node:crypto").then((crypto) => crypto.webcrypto as Crypto),
|
|
18
|
+
writable: false,
|
|
19
|
+
configurable: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Database setup
|
|
25
|
+
*
|
|
26
|
+
* @link {@see https://lucia-auth.com/database/#database-setup}
|
|
27
|
+
**/
|
|
28
|
+
const adapter = BATI.has("drizzle")
|
|
29
|
+
? new DrizzleSQLiteAdapter(drizzleDb, sessionTable, userTable)
|
|
30
|
+
: new BetterSqlite3Adapter(sqliteDb, {
|
|
31
|
+
user: "users",
|
|
32
|
+
session: "sessions",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initialize Lucia
|
|
37
|
+
*
|
|
38
|
+
* @link {@see https://lucia-auth.com/getting-started/#initialize-lucia}
|
|
39
|
+
*/
|
|
40
|
+
export const lucia = new Lucia(adapter, {
|
|
41
|
+
/**
|
|
42
|
+
* Lucia Configuration
|
|
43
|
+
*
|
|
44
|
+
* @link {@see https://lucia-auth.com/basics/configuration}
|
|
45
|
+
*/
|
|
46
|
+
sessionCookie: {
|
|
47
|
+
attributes: {
|
|
48
|
+
secure: process.env.NODE_ENV === "production",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
getUserAttributes: (attributes) => {
|
|
52
|
+
return {
|
|
53
|
+
username: attributes.username,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Initialize OAuth provider
|
|
60
|
+
*
|
|
61
|
+
* @link {@see https://lucia-auth.com/guides/oauth/basics#initialize-oauth-provider}
|
|
62
|
+
*/
|
|
63
|
+
export const github = new GitHub(process.env.GITHUB_CLIENT_ID as string, process.env.GITHUB_CLIENT_SECRET as string);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Define user attributes
|
|
67
|
+
*
|
|
68
|
+
* @link {@see https://lucia-auth.com/basics/users#define-user-attributes}
|
|
69
|
+
*/
|
|
70
|
+
declare module "lucia" {
|
|
71
|
+
interface Register {
|
|
72
|
+
Lucia: typeof lucia;
|
|
73
|
+
DatabaseUserAttributes: Omit<DatabaseUser, "id">;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DatabaseUser {
|
|
78
|
+
id: string;
|
|
79
|
+
username: string;
|
|
80
|
+
password?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DatabaseOAuthAccount {
|
|
84
|
+
provider_id: string;
|
|
85
|
+
provider_user_id: string;
|
|
86
|
+
/*{ @if (it.BATI.has("drizzle")) }*/
|
|
87
|
+
userId: string;
|
|
88
|
+
/*{ #else }*/
|
|
89
|
+
user_id: string;
|
|
90
|
+
/*{ /if }*/
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface GitHubUser {
|
|
94
|
+
id: number;
|
|
95
|
+
login: string; // username
|
|
96
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// https://vike.dev/guard
|
|
2
|
+
import { redirect } from "vike/abort";
|
|
3
|
+
import type { GuardAsync } from "vike/types";
|
|
4
|
+
|
|
5
|
+
const guard: GuardAsync = async (pageContext): ReturnType<GuardAsync> => {
|
|
6
|
+
if (pageContext.user) {
|
|
7
|
+
throw redirect("/");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { guard };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
header {
|
|
2
|
+
font-size: 28px;
|
|
3
|
+
font-weight: 600;
|
|
4
|
+
text-align: center;
|
|
5
|
+
}
|
|
6
|
+
.form {
|
|
7
|
+
position: absolute;
|
|
8
|
+
max-width: 430px;
|
|
9
|
+
width: 100%;
|
|
10
|
+
}
|
|
11
|
+
.form .field {
|
|
12
|
+
position: relative;
|
|
13
|
+
height: 50px;
|
|
14
|
+
width: 100%;
|
|
15
|
+
margin-top: 20px;
|
|
16
|
+
border-radius: 6px;
|
|
17
|
+
}
|
|
18
|
+
.field input,
|
|
19
|
+
.button-field {
|
|
20
|
+
height: 100%;
|
|
21
|
+
width: 100%;
|
|
22
|
+
border: none;
|
|
23
|
+
font-size: 16px;
|
|
24
|
+
font-weight: 400;
|
|
25
|
+
border-radius: 6px;
|
|
26
|
+
}
|
|
27
|
+
.button-group {
|
|
28
|
+
display: flex;
|
|
29
|
+
}
|
|
30
|
+
.login-button {
|
|
31
|
+
background-color: #0171d3e8;
|
|
32
|
+
}
|
|
33
|
+
.login-button:hover {
|
|
34
|
+
background-color: #016dcb;
|
|
35
|
+
}
|
|
36
|
+
.signup-button {
|
|
37
|
+
background-color: #d30101f6;
|
|
38
|
+
}
|
|
39
|
+
.signup-button:hover {
|
|
40
|
+
background-color: #cb010b;
|
|
41
|
+
}
|
|
42
|
+
.field input {
|
|
43
|
+
outline: none;
|
|
44
|
+
padding: 0 15px;
|
|
45
|
+
border: 1px solid#CACACA;
|
|
46
|
+
}
|
|
47
|
+
.field input:focus {
|
|
48
|
+
border-bottom-width: 2px;
|
|
49
|
+
}
|
|
50
|
+
.field button {
|
|
51
|
+
color: #fff;
|
|
52
|
+
margin: 0 2px;
|
|
53
|
+
transition: all 0.3s ease;
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
}
|
|
56
|
+
.field-error {
|
|
57
|
+
display: block;
|
|
58
|
+
width: 100%;
|
|
59
|
+
margin-top: 0.25rem;
|
|
60
|
+
font-size: 85%;
|
|
61
|
+
color: #dc3545;
|
|
62
|
+
}
|
|
63
|
+
.media-options a {
|
|
64
|
+
display: flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: center;
|
|
67
|
+
}
|
|
68
|
+
a.github {
|
|
69
|
+
color: #fff;
|
|
70
|
+
background-color: #000;
|
|
71
|
+
}
|
|
72
|
+
a.github .github-icon {
|
|
73
|
+
height: 28px;
|
|
74
|
+
width: 28px;
|
|
75
|
+
color: #000;
|
|
76
|
+
font-size: 20px;
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: center;
|
|
81
|
+
background-color: #fff;
|
|
82
|
+
}
|
|
83
|
+
.github-icon {
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: 50%;
|
|
86
|
+
left: 15px;
|
|
87
|
+
transform: translateY(-50%);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@media screen and (max-width: 400px) {
|
|
91
|
+
.form {
|
|
92
|
+
padding: 20px 10px;
|
|
93
|
+
}
|
|
94
|
+
}
|