sveltekit-auth-example 1.0.6 → 1.0.9
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/CHANGELOG.md +8 -0
- package/README.md +5 -5
- package/db_create.sql +6 -6
- package/package.json +22 -19
- package/src/app.html +3 -3
- package/svelte.config.js +1 -5
- package/tsconfig.json +7 -26
- package/vite.config.js +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 1.0.9
|
|
2
|
+
* Bump dependencies
|
|
3
|
+
* Adjust for changes to SvelteKit with respect to vite
|
|
4
|
+
|
|
5
|
+
# 1.0.7
|
|
6
|
+
* Bump dependencies and verify against latest SvelteKit
|
|
7
|
+
* Additional changes for register PostgreSQL function
|
|
8
|
+
|
|
1
9
|
# 1.0.5
|
|
2
10
|
* Bump dependencies
|
|
3
11
|
* [Fix] Flaw in register allowing user to register over top of an existing account
|
package/README.md
CHANGED
|
@@ -30,9 +30,9 @@ Pages use the session.user.role to determine whether they are authorized. While
|
|
|
30
30
|
The forgot password functionality uses SendInBlue to send the email. You would need to have a SendInBlue account and set three environmental variables. Email sending is in /src/routes/auth/forgot.ts. This code could easily be replaced by nodemailer or something similar.
|
|
31
31
|
|
|
32
32
|
## Prerequisites
|
|
33
|
-
- PostgreSQL
|
|
34
|
-
- Node.js 16.
|
|
35
|
-
- npm 8.
|
|
33
|
+
- PostgreSQL 14 or higher
|
|
34
|
+
- Node.js 16.16.0 or higher
|
|
35
|
+
- npm 8.14.0 or higher
|
|
36
36
|
- Google API client
|
|
37
37
|
- SendInBlue account (only used for emailing password reset link - the sample can run without it but forgot password will not work)
|
|
38
38
|
|
|
@@ -53,7 +53,7 @@ npm install
|
|
|
53
53
|
psql -d postgres -f db_create.sql
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
2. Create a **Google API client ID** per [these instructions](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid).
|
|
56
|
+
2. Create a **Google API client ID** per [these instructions](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid). Make sure you include `http://localhost:3000`, `http://localhost` in the Authorized JavaScript origins and `http://localhost:3000/auth/google/callback` in the Authorized redirect URIs for your Client ID for Web application. ** Do not access the site using http://127.0.0.1:3000 ** - use `http://localhost:3000` or it will not work.
|
|
57
57
|
|
|
58
58
|
3. Create an **.env** file at the top level of the project with the following values (substituting your own id and PostgreSQL username and password):
|
|
59
59
|
```bash
|
|
@@ -83,4 +83,4 @@ The db_create.sql script adds three users to the database with obvious roles:
|
|
|
83
83
|
|
|
84
84
|
## My ask of you
|
|
85
85
|
|
|
86
|
-
Please report any issues or areas where the code can be optimized.
|
|
86
|
+
Please report any issues or areas where the code can be optimized.
|
package/db_create.sql
CHANGED
|
@@ -182,15 +182,17 @@ DECLARE
|
|
|
182
182
|
input_phone varchar(23) := TRIM((input->>'phone')::varchar);
|
|
183
183
|
input_password varchar(80) := (input->>'password')::varchar;
|
|
184
184
|
BEGIN
|
|
185
|
-
|
|
185
|
+
PERFORM id FROM users WHERE email = input_email;
|
|
186
186
|
IF NOT FOUND THEN
|
|
187
187
|
INSERT INTO users(role, password, email, first_name, last_name, phone)
|
|
188
|
-
VALUES('student', crypt(input_password,
|
|
188
|
+
VALUES('student', crypt(input_password, gen_salt('bf', 8)), input_email, input_first_name, input_last_name, input_phone)
|
|
189
189
|
RETURNING
|
|
190
190
|
json_build_object(
|
|
191
191
|
'sessionId', create_session(users.id),
|
|
192
|
-
'user', json_build_object('id', users.id, 'role', 'student', 'email', input_email, 'firstName', input_first_name, 'lastName', input_last_name, 'phone', input_phone)
|
|
192
|
+
'user', json_build_object('id', users.id, 'role', 'student', 'email', input_email, 'firstName', input_first_name, 'lastName', input_last_name, 'phone', input_phone, 'optOut', false)
|
|
193
193
|
) INTO user_session;
|
|
194
|
+
ELSE -- user is registering account that already exists so set sessionId and user to null so client can let them know
|
|
195
|
+
SELECT authenticate(input) INTO user_session;
|
|
194
196
|
END IF;
|
|
195
197
|
END;
|
|
196
198
|
$BODY$;
|
|
@@ -210,7 +212,7 @@ DECLARE
|
|
|
210
212
|
input_first_name varchar(20) := TRIM((input->>'firstName')::varchar);
|
|
211
213
|
input_last_name varchar(20) := TRIM((input->>'lastName')::varchar);
|
|
212
214
|
BEGIN
|
|
213
|
-
|
|
215
|
+
SELECT json_build_object('id', create_session(users.id), 'user', json_build_object('id', users.id, 'role', users.role, 'email', input_email, 'firstName', users.first_name, 'lastName', users.last_name, 'phone', users.phone)) INTO user_session FROM users WHERE email = input_email;
|
|
214
216
|
IF NOT FOUND THEN
|
|
215
217
|
INSERT INTO users(role, email, first_name, last_name)
|
|
216
218
|
VALUES('student', input_email, input_first_name, input_last_name)
|
|
@@ -219,8 +221,6 @@ BEGIN
|
|
|
219
221
|
'id', create_session(users.id),
|
|
220
222
|
'user', json_build_object('id', users.id, 'role', 'student', 'email', input_email, 'firstName', input_first_name, 'lastName', input_last_name, 'phone', null)
|
|
221
223
|
) INTO user_session;
|
|
222
|
-
ELSE
|
|
223
|
-
SELECT authenticate(input) INTO user_session;
|
|
224
224
|
END IF;
|
|
225
225
|
END;
|
|
226
226
|
$BODY$;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sveltekit-auth-example",
|
|
3
3
|
"description": "SvelteKit Authentication Example",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Nate Stuyvesant",
|
|
7
7
|
"license": "https://github.com/nstuyvesant/sveltekit-auth-example/blob/master/LICENSE",
|
|
@@ -22,24 +22,25 @@
|
|
|
22
22
|
"example"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
25
|
+
"start": "node build",
|
|
26
|
+
"dev": "vite dev",
|
|
26
27
|
"serve": "npm run dev -- --open",
|
|
27
|
-
"build": "
|
|
28
|
-
"preview": "
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"preview": "vite preview",
|
|
29
30
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
30
31
|
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
|
31
32
|
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
|
|
32
33
|
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
|
|
33
34
|
},
|
|
34
35
|
"engines": {
|
|
35
|
-
"node": "~16.
|
|
36
|
-
"npm": "^8.
|
|
36
|
+
"node": "~16.16.0",
|
|
37
|
+
"npm": "^8.14.0"
|
|
37
38
|
},
|
|
38
39
|
"type": "module",
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"cookie": "^0.5.0",
|
|
41
|
-
"dotenv": "^16.0.
|
|
42
|
-
"google-auth-library": "^8.
|
|
42
|
+
"dotenv": "^16.0.1",
|
|
43
|
+
"google-auth-library": "^8.1.1",
|
|
43
44
|
"jsonwebtoken": "^8.5.1",
|
|
44
45
|
"pg": "^8.7.3",
|
|
45
46
|
"pg-native": "^3.0.0"
|
|
@@ -47,22 +48,24 @@
|
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@sveltejs/adapter-node": "latest",
|
|
49
50
|
"@sveltejs/kit": "latest",
|
|
51
|
+
"@types/cookie": "^0.5.1",
|
|
50
52
|
"@types/jsonwebtoken": "^8.5.8",
|
|
51
53
|
"@types/pg": "^8.6.5",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
53
|
-
"@typescript-eslint/parser": "^5.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
|
55
|
+
"@typescript-eslint/parser": "^5.30.6",
|
|
54
56
|
"bootstrap": "^5.1.3",
|
|
55
|
-
"bootstrap-icons": "^1.
|
|
56
|
-
"eslint": "^8.
|
|
57
|
+
"bootstrap-icons": "^1.9.0",
|
|
58
|
+
"eslint": "^8.19.0",
|
|
57
59
|
"eslint-config-prettier": "^8.5.0",
|
|
58
|
-
"eslint-plugin-svelte3": "^
|
|
59
|
-
"prettier": "^2.
|
|
60
|
+
"eslint-plugin-svelte3": "^4.0.0",
|
|
61
|
+
"prettier": "^2.7.1",
|
|
60
62
|
"prettier-plugin-svelte": "^2.7.0",
|
|
61
|
-
"sass": "^1.
|
|
62
|
-
"svelte": "^3.
|
|
63
|
-
"svelte-check": "^2.
|
|
64
|
-
"svelte-preprocess": "^4.10.
|
|
63
|
+
"sass": "^1.53.0",
|
|
64
|
+
"svelte": "^3.49.0",
|
|
65
|
+
"svelte-check": "^2.8.0",
|
|
66
|
+
"svelte-preprocess": "^4.10.7",
|
|
65
67
|
"tslib": "^2.4.0",
|
|
66
|
-
"typescript": "^4.
|
|
68
|
+
"typescript": "^4.7.4",
|
|
69
|
+
"vite": "^3.0.0"
|
|
67
70
|
}
|
|
68
71
|
}
|
package/src/app.html
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<link rel="icon" href="/favicon.png" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
-
%
|
|
7
|
+
%sveltekit.head%
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
|
-
<div id="svelte">%
|
|
10
|
+
<div id="svelte">%sveltekit.body%</div>
|
|
11
11
|
</body>
|
|
12
|
-
</html>
|
|
12
|
+
</html>
|
package/svelte.config.js
CHANGED
|
@@ -5,6 +5,7 @@ const production = process.env.NODE_ENV === 'production'
|
|
|
5
5
|
|
|
6
6
|
const baseCsp = [
|
|
7
7
|
'self',
|
|
8
|
+
'ws://127.0.0.1:3000/',
|
|
8
9
|
// 'strict-dynamic', // issues with datepicker on classes, add to calendar scripts
|
|
9
10
|
'https://www.gstatic.com/recaptcha/', // recaptcha
|
|
10
11
|
'https://accounts.google.com/gsi/', // sign-in w/google
|
|
@@ -33,11 +34,6 @@ const config = {
|
|
|
33
34
|
'base-uri': ['self'],
|
|
34
35
|
// 'require-trusted-types-for': ["'script'"] // will require effort to get this working
|
|
35
36
|
}
|
|
36
|
-
},
|
|
37
|
-
vite: {
|
|
38
|
-
serviceWorker: {
|
|
39
|
-
files: (filepath) => !/\.DS_Store/.test(filepath)
|
|
40
|
-
}
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "./.svelte-kit/tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "node",
|
|
5
|
-
"module": "es2020",
|
|
6
|
-
"lib": ["es2020", "DOM"],
|
|
7
|
-
"target": "es2019",
|
|
8
|
-
/**
|
|
9
|
-
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
|
|
10
|
-
to enforce using \`import type\` instead of \`import\` for Types.
|
|
11
|
-
*/
|
|
12
|
-
"importsNotUsedAsValues": "error",
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
/**
|
|
16
|
-
To have warnings/errors of the Svelte compiler at the correct position,
|
|
17
|
-
enable source maps by default.
|
|
18
|
-
*/
|
|
19
|
-
"sourceMap": true,
|
|
20
|
-
"esModuleInterop": true,
|
|
21
|
-
"skipLibCheck": true,
|
|
22
|
-
"forceConsistentCasingInFileNames": true,
|
|
23
|
-
"baseUrl": ".",
|
|
24
4
|
"allowJs": true,
|
|
25
5
|
"checkJs": true,
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"strict": true
|
|
12
|
+
}
|
|
32
13
|
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sveltekit } from '@sveltejs/kit/vite'
|
|
2
|
+
|
|
3
|
+
/** @type {import('vite').UserConfig} */
|
|
4
|
+
const config = {
|
|
5
|
+
plugins: [sveltekit()],
|
|
6
|
+
serviceWorker: {
|
|
7
|
+
files: (filepath) => !/\.DS_Store/.test(filepath)
|
|
8
|
+
},
|
|
9
|
+
server: {
|
|
10
|
+
host: 'localhost',
|
|
11
|
+
port: 3000,
|
|
12
|
+
open: 'http://localhost:3000'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default config
|