sveltekit-auth-example 1.0.31 → 1.0.33
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 +9 -0
- package/README.md +2 -2
- package/package.json +11 -11
- package/src/app.d.ts +0 -13
- package/src/lib/google.ts +1 -1
- package/src/routes/+layout.svelte +0 -21
- package/static/apple-touch-icon.png +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# Backlog
|
|
2
2
|
* Add password complexity checking on /register and /profile pages (only checks for length currently despite what the pages say)
|
|
3
3
|
|
|
4
|
+
# 1.0.33
|
|
5
|
+
* Update dependencies
|
|
6
|
+
|
|
7
|
+
# 1.0.32
|
|
8
|
+
* Remove window from reference to google.accounts
|
|
9
|
+
* Add apple-touch-icon.png
|
|
10
|
+
* Update dependencies
|
|
11
|
+
* Remove dead code
|
|
12
|
+
|
|
4
13
|
# 1.0.31
|
|
5
14
|
* Cleanup
|
|
6
15
|
* Update SvelteKit
|
package/README.md
CHANGED
|
@@ -27,12 +27,12 @@ The website supports two types of authentication:
|
|
|
27
27
|
|
|
28
28
|
> There is some overhead to checking the user session in a database each time versus using a JWT; however, validating each request avoids problems discussed in [this article](https://redis.com/blog/json-web-tokens-jwt-are-dangerous-for-user-sessions/) and [this one](https://scotch.io/bar-talk/why-jwts-suck-as-session-tokens). For a high-volume website, I would use Redis or the equivalent.
|
|
29
29
|
|
|
30
|
-
The forgot password / password reset functionality uses a JWT and [**SendInBlue**](https://www.sendinblue.com) 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. Note: I have no affliation with **SendInBlue** (used their API
|
|
30
|
+
The forgot password / password reset functionality uses a JWT and [**SendInBlue**](https://www.sendinblue.com) 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. Note: I have no affliation with **SendInBlue** (used their API in another project).
|
|
31
31
|
|
|
32
32
|
## Prerequisites
|
|
33
33
|
- PostgreSQL 14.5 or higher
|
|
34
34
|
- Node.js 18.11.0 or higher
|
|
35
|
-
- npm
|
|
35
|
+
- npm 9.1.1 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
|
|
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.33",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Nate Stuyvesant",
|
|
7
7
|
"license": "https://github.com/nstuyvesant/sveltekit-auth-example/blob/master/LICENSE",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"format": "prettier --write ."
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": "
|
|
36
|
-
"npm": "^
|
|
35
|
+
"node": ">=18.11.0",
|
|
36
|
+
"npm": "^9.1.1"
|
|
37
37
|
},
|
|
38
38
|
"type": "module",
|
|
39
39
|
"dependencies": {
|
|
@@ -42,26 +42,26 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@sveltejs/adapter-node": "latest",
|
|
44
44
|
"@sveltejs/kit": "latest",
|
|
45
|
-
"@types/bootstrap": "5.2.
|
|
45
|
+
"@types/bootstrap": "5.2.6",
|
|
46
46
|
"@types/google.accounts": "0.0.2",
|
|
47
47
|
"@types/jsonwebtoken": "^8.5.9",
|
|
48
48
|
"@types/pg": "^8.6.5",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^5.42.
|
|
50
|
-
"@typescript-eslint/parser": "^5.42.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
50
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
51
51
|
"bootstrap": "^5.2.2",
|
|
52
|
-
"eslint": "^8.
|
|
52
|
+
"eslint": "^8.27.0",
|
|
53
53
|
"eslint-config-prettier": "^8.5.0",
|
|
54
54
|
"eslint-plugin-svelte3": "^4.0.0",
|
|
55
|
-
"google-auth-library": "^8.
|
|
55
|
+
"google-auth-library": "^8.7.0",
|
|
56
56
|
"jsonwebtoken": "^8.5.1",
|
|
57
57
|
"prettier": "^2.7.1",
|
|
58
58
|
"prettier-plugin-svelte": "^2.8.0",
|
|
59
|
-
"sass": "^1.
|
|
60
|
-
"svelte": "^3.
|
|
59
|
+
"sass": "^1.56.1",
|
|
60
|
+
"svelte": "^3.53.1",
|
|
61
61
|
"svelte-check": "^2.9.2",
|
|
62
62
|
"svelte-preprocess": "^4.10.7",
|
|
63
63
|
"tslib": "^2.4.1",
|
|
64
64
|
"typescript": "^4.8.4",
|
|
65
|
-
"vite": "^3.2.
|
|
65
|
+
"vite": "^3.2.3"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/app.d.ts
CHANGED
|
@@ -40,19 +40,6 @@ interface Credentials {
|
|
|
40
40
|
password: string
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
interface GoogleCredentialResponse {
|
|
44
|
-
credential: string
|
|
45
|
-
select_by:
|
|
46
|
-
| 'auto'
|
|
47
|
-
| 'user'
|
|
48
|
-
| 'user_1tap'
|
|
49
|
-
| 'user_2tap'
|
|
50
|
-
| 'btn'
|
|
51
|
-
| 'btn_confirm'
|
|
52
|
-
| 'btn_add_session'
|
|
53
|
-
| 'btn_confirm_add_session'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
43
|
interface MessageAddressee {
|
|
57
44
|
email: string
|
|
58
45
|
name?: string
|
package/src/lib/google.ts
CHANGED
|
@@ -35,27 +35,6 @@
|
|
|
35
35
|
if (!$loginSession) google.accounts.id.prompt()
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
async function googleCallback(response: google.accounts.id.CredentialResponse) {
|
|
39
|
-
const res = await fetch('/auth/google', {
|
|
40
|
-
method: 'POST',
|
|
41
|
-
headers: {
|
|
42
|
-
'Content-Type': 'application/json'
|
|
43
|
-
},
|
|
44
|
-
body: JSON.stringify({ token: response.credential })
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
if (res.ok) {
|
|
48
|
-
const fromEndpoint = await res.json()
|
|
49
|
-
loginSession.set(fromEndpoint.user) // update loginSession store
|
|
50
|
-
const { role } = fromEndpoint.user
|
|
51
|
-
const referrer = $page.url.searchParams.get('referrer')
|
|
52
|
-
if (referrer) return goto(referrer)
|
|
53
|
-
if (role === 'teacher') return goto('/teachers')
|
|
54
|
-
if (role === 'admin') return goto('/admin')
|
|
55
|
-
if (location.pathname === '/login') goto('/') // logged in so go home
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
38
|
async function logout() {
|
|
60
39
|
// Request server delete httpOnly cookie called loginSession
|
|
61
40
|
const url = '/auth/logout'
|
|
Binary file
|