sveltekit-auth-example 1.0.3 → 1.0.6

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 CHANGED
@@ -1,3 +1,15 @@
1
+ # 1.0.5
2
+ * Bump dependencies
3
+ * [Fix] Flaw in register allowing user to register over top of an existing account
4
+ * Additional checks of submitted data
5
+
6
+ # 1.0.4
7
+ * Bump dependencies
8
+
9
+ # 1.0.4
10
+ * [Fix] If you login with a Google account, you cannot Update the Profile (UI is looking for password and confirm password which don't make sense in this context)
11
+ * Added Content Security Policy
12
+
1
13
  # 1.0.3
2
14
  * [Fix] user created or updated when password mismatches (@lxy-yz)
3
15
  * Updated project dependencies
@@ -5,18 +17,15 @@
5
17
  * Added declarations for Session and Locals for type safety
6
18
 
7
19
  # 1.0.2
8
-
9
20
  * [Fix] Updated endpoints and hooks to conform to SvelteKit's API changes.
10
21
  * Updated project dependencies
11
22
 
12
23
  # 1.0.1
13
-
14
24
  * Switched to dotenv vs. VITE_ env values for better security
15
25
  * Load Sign in with Google via code instead of static template
16
26
  * Fix logout (didn't work if session expired)
17
27
  * Fix login button rendering if that's the starting page
18
28
 
19
29
  # Backlog
20
-
21
30
  * [Low] Add password complexity check
22
31
  * [Low] Add Google reCaptcha 3
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Nate Stuyvesant
3
+ Copyright (c) 2022 Nate Stuyvesant
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/db_create.sql CHANGED
@@ -210,7 +210,7 @@ DECLARE
210
210
  input_first_name varchar(20) := TRIM((input->>'firstName')::varchar);
211
211
  input_last_name varchar(20) := TRIM((input->>'lastName')::varchar);
212
212
  BEGIN
213
- 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;
213
+ PERFORM id FROM users WHERE email = input_email;
214
214
  IF NOT FOUND THEN
215
215
  INSERT INTO users(role, email, first_name, last_name)
216
216
  VALUES('student', input_email, input_first_name, input_last_name)
@@ -219,6 +219,8 @@ BEGIN
219
219
  'id', create_session(users.id),
220
220
  'user', json_build_object('id', users.id, 'role', 'student', 'email', input_email, 'firstName', input_first_name, 'lastName', input_last_name, 'phone', null)
221
221
  ) INTO user_session;
222
+ ELSE
223
+ SELECT authenticate(input) INTO user_session;
222
224
  END IF;
223
225
  END;
224
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.3",
4
+ "version": "1.0.6",
5
5
  "private": false,
6
6
  "author": "Nate Stuyvesant",
7
7
  "license": "https://github.com/nstuyvesant/sveltekit-auth-example/blob/master/LICENSE",
@@ -12,6 +12,15 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/nstuyvesant/sveltekit-auth-example/issues"
14
14
  },
15
+ "keywords": [
16
+ "svelte",
17
+ "sveltekit",
18
+ "authentication",
19
+ "example",
20
+ "google",
21
+ "postgresql",
22
+ "example"
23
+ ],
15
24
  "scripts": {
16
25
  "dev": "svelte-kit dev",
17
26
  "serve": "npm run dev -- --open",
@@ -24,36 +33,36 @@
24
33
  },
25
34
  "engines": {
26
35
  "node": "~16.14.2",
27
- "npm": "^8.6.0"
36
+ "npm": "^8.8.0"
28
37
  },
29
38
  "type": "module",
30
39
  "dependencies": {
31
- "cookie": "^0.4.2",
40
+ "cookie": "^0.5.0",
32
41
  "dotenv": "^16.0.0",
33
- "google-auth-library": "^7.11.1",
42
+ "google-auth-library": "^8.0.1",
34
43
  "jsonwebtoken": "^8.5.1",
35
44
  "pg": "^8.7.3",
36
45
  "pg-native": "^3.0.0"
37
46
  },
38
47
  "devDependencies": {
39
- "@sveltejs/adapter-node": "next",
40
- "@sveltejs/kit": "next",
48
+ "@sveltejs/adapter-node": "latest",
49
+ "@sveltejs/kit": "latest",
41
50
  "@types/jsonwebtoken": "^8.5.8",
42
51
  "@types/pg": "^8.6.5",
43
- "@typescript-eslint/eslint-plugin": "^5.18.0",
44
- "@typescript-eslint/parser": "^5.18.0",
52
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
53
+ "@typescript-eslint/parser": "^5.21.0",
45
54
  "bootstrap": "^5.1.3",
46
55
  "bootstrap-icons": "^1.8.1",
47
- "eslint": "^8.12.0",
56
+ "eslint": "^8.14.0",
48
57
  "eslint-config-prettier": "^8.5.0",
49
58
  "eslint-plugin-svelte3": "^3.4.1",
50
59
  "prettier": "^2.6.2",
51
- "prettier-plugin-svelte": "^2.6.0",
52
- "sass": "^1.49.11",
53
- "svelte": "^3.46.6",
54
- "svelte-check": "^2.4.6",
55
- "svelte-preprocess": "^4.10.5",
56
- "tslib": "^2.3.1",
60
+ "prettier-plugin-svelte": "^2.7.0",
61
+ "sass": "^1.51.0",
62
+ "svelte": "^3.47.0",
63
+ "svelte-check": "^2.7.0",
64
+ "svelte-preprocess": "^4.10.6",
65
+ "tslib": "^2.4.0",
57
66
  "typescript": "^4.6.3"
58
67
  }
59
68
  }
@@ -9,12 +9,6 @@ export const post: RequestHandler = async event => {
9
9
 
10
10
  try {
11
11
  switch (slug) {
12
- case 'login':
13
- sql = `SELECT authenticate($1) AS "authenticationResult";`
14
- break
15
- case 'register':
16
- sql = `SELECT register($1) AS "authenticationResult";`
17
- break
18
12
  case 'logout':
19
13
  if (event.locals.user) { // if user is null, they are logged out anyway (session might have ended)
20
14
  sql = `CALL delete_session($1);`
@@ -29,6 +23,13 @@ export const post: RequestHandler = async event => {
29
23
  message: 'Logout successful.'
30
24
  }
31
25
  }
26
+ case 'login':
27
+ sql = `SELECT authenticate($1) AS "authenticationResult";`
28
+ break
29
+ case 'register':
30
+ sql = `SELECT register($1) AS "authenticationResult";`
31
+ break
32
+
32
33
  default:
33
34
  return {
34
35
  status: 404,
@@ -41,8 +42,18 @@ export const post: RequestHandler = async event => {
41
42
 
42
43
  // Only /auth/login and /auth/register at this point
43
44
  const body = await event.request.json()
44
- result = await query(sql, [JSON.stringify(body)])
45
45
 
46
+ // While client checks for these to be non-null, register() in the database does not
47
+ if (slug == 'register' && (!body.email || !body.password || !body.firstName || !body.lastName))
48
+ return {
49
+ status: 400,
50
+ body: {
51
+ message: 'Please supply all required fields: email, password, first and last name.',
52
+ user: null
53
+ }
54
+ }
55
+
56
+ result = await query(sql, [JSON.stringify(body)])
46
57
  } catch (error) {
47
58
  return {
48
59
  status: 503,
@@ -32,7 +32,7 @@
32
32
  message = ''
33
33
  const form = document.forms['profile']
34
34
 
35
- if (!passwordMatch()) {
35
+ if (!user.email.includes('gmail.com') && !passwordMatch()) {
36
36
  confirmPassword.classList.add('is-invalid')
37
37
  return
38
38
  }
package/svelte.config.js CHANGED
@@ -1,6 +1,19 @@
1
1
  import adapter from '@sveltejs/adapter-node'
2
2
  import preprocess from 'svelte-preprocess'
3
3
 
4
+ const production = process.env.NODE_ENV === 'production'
5
+
6
+ const baseCsp = [
7
+ 'self',
8
+ // 'strict-dynamic', // issues with datepicker on classes, add to calendar scripts
9
+ 'https://www.gstatic.com/recaptcha/', // recaptcha
10
+ 'https://accounts.google.com/gsi/', // sign-in w/google
11
+ 'https://www.google.com/recaptcha/', // recapatcha
12
+ 'https://fonts.gstatic.com/' // recaptcha fonts
13
+ ]
14
+
15
+ if (!production) baseCsp.push('ws://localhost:3000')
16
+
4
17
  /** @type {import('@sveltejs/kit').Config} */
5
18
  const config = {
6
19
  preprocess: preprocess(),
@@ -8,7 +21,24 @@ const config = {
8
21
  kit: {
9
22
  adapter: adapter({
10
23
  out: 'build'
11
- })
24
+ }),
25
+ csp: {
26
+ mode: 'auto',
27
+ directives: {
28
+ 'default-src': [...baseCsp],
29
+ 'script-src': ['unsafe-inline', ...baseCsp],
30
+ 'img-src': ['data:', 'blob:', ...baseCsp],
31
+ 'style-src': ['unsafe-inline', ...baseCsp],
32
+ 'object-src': ['none'],
33
+ 'base-uri': ['self'],
34
+ // 'require-trusted-types-for': ["'script'"] // will require effort to get this working
35
+ }
36
+ },
37
+ vite: {
38
+ serviceWorker: {
39
+ files: (filepath) => !/\.DS_Store/.test(filepath)
40
+ }
41
+ }
12
42
  }
13
43
  }
14
44