sveltekit-auth-example 1.0.22 → 1.0.23
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 +4 -0
- package/package.json +4 -4
- package/src/app.d.ts +2 -2
- package/src/hooks.server.ts +1 -1
- package/src/lib/auth.ts +1 -1
- package/src/{routes/_db.ts → lib/server/db.ts} +0 -0
- package/src/{routes/_send-in-blue.ts → lib/server/send-in-blue.ts} +0 -0
- package/src/routes/+layout.server.ts +2 -3
- package/src/routes/admin/+page.server.ts +1 -1
- package/src/routes/api/v1/user/+server.ts +2 -2
- package/src/routes/auth/[slug]/+server.ts +3 -4
- package/src/routes/auth/forgot/+server.ts +2 -3
- package/src/routes/auth/google/+server.ts +2 -2
- package/src/routes/auth/reset/+server.ts +1 -1
- package/src/routes/register/+page.svelte +0 -1
- package/src/routes/teachers/+page.server.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
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.23
|
|
5
|
+
* Restructured server-side libraries to $lib/server based on https://github.com/sveltejs/kit/pull/6623
|
|
6
|
+
* General cleanup
|
|
7
|
+
|
|
4
8
|
# 1.0.22
|
|
5
9
|
* Move google-auth-library and jsonwebtoken to devDependencies from dependencies and other cleanup to package.json
|
|
6
10
|
|
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.23",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Nate Stuyvesant",
|
|
7
7
|
"license": "https://github.com/nstuyvesant/sveltekit-auth-example/blob/master/LICENSE",
|
|
@@ -46,10 +46,10 @@
|
|
|
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.
|
|
50
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.37.0",
|
|
51
51
|
"bootstrap": "^5.2.1",
|
|
52
|
-
"eslint": "^8.23.
|
|
52
|
+
"eslint": "^8.23.1",
|
|
53
53
|
"eslint-config-prettier": "^8.5.0",
|
|
54
54
|
"eslint-plugin-svelte3": "^4.0.0",
|
|
55
55
|
"google-auth-library": "^8.5.1",
|
package/src/app.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare namespace App {
|
|
|
13
13
|
|
|
14
14
|
// interface Platform {}
|
|
15
15
|
|
|
16
|
-
interface PrivateEnv { // $env/
|
|
16
|
+
interface PrivateEnv { // $env/static/private
|
|
17
17
|
DATABASE_URL: string
|
|
18
18
|
DOMAIN: string
|
|
19
19
|
JWT_SECRET: string
|
|
@@ -23,7 +23,7 @@ declare namespace App {
|
|
|
23
23
|
SEND_IN_BLUE_ADMINS: string
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
interface PublicEnv { // $env/
|
|
26
|
+
interface PublicEnv { // $env/static/public
|
|
27
27
|
PUBLIC_GOOGLE_CLIENT_ID: string
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/hooks.server.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Handle, RequestEvent } from '@sveltejs/kit'
|
|
2
|
-
import { query } from '
|
|
2
|
+
import { query } from '$lib/server/db'
|
|
3
3
|
|
|
4
4
|
// Attach authorization to each server request (role may have changed)
|
|
5
5
|
async function attachUserToRequestEvent(sessionId: string, event: RequestEvent) {
|
package/src/lib/auth.ts
CHANGED
|
@@ -62,7 +62,7 @@ export default function useAuth(
|
|
|
62
62
|
try {
|
|
63
63
|
const res = await fetch('/auth/register', {
|
|
64
64
|
method: 'POST',
|
|
65
|
-
body: JSON.stringify(user), // server
|
|
65
|
+
body: JSON.stringify(user), // server ignores user.role - always set it to 'student' (lowest priv)
|
|
66
66
|
headers: {
|
|
67
67
|
'Content-Type': 'application/json'
|
|
68
68
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { LayoutServerLoad } from './$types'
|
|
2
2
|
|
|
3
|
-
export const load: LayoutServerLoad = (
|
|
4
|
-
const
|
|
5
|
-
const { user }: { user: User } = locals // locals.user set by hooks.ts/handle(), undefined if not logged in
|
|
3
|
+
export const load: LayoutServerLoad = ({ locals }) => {
|
|
4
|
+
const { user } = locals // locals.user set by hooks.server.ts/handle(), undefined if not logged in
|
|
6
5
|
return {
|
|
7
6
|
user
|
|
8
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { error, json} from '@sveltejs/kit'
|
|
1
|
+
import { error, json } from '@sveltejs/kit'
|
|
2
2
|
import type { RequestHandler } from './$types'
|
|
3
|
-
import { query } from '
|
|
3
|
+
import { query } from '$lib/server/db'
|
|
4
4
|
|
|
5
5
|
export const PUT: RequestHandler = async event => {
|
|
6
6
|
const { user } = event.locals
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { error, json } from '@sveltejs/kit'
|
|
2
2
|
import type { RequestHandler } from './$types'
|
|
3
|
-
import { query } from '
|
|
3
|
+
import { query } from '$lib/server/db'
|
|
4
4
|
|
|
5
5
|
export const POST: RequestHandler = async (event) => {
|
|
6
6
|
const { slug } = event.params
|
|
@@ -11,8 +11,7 @@ export const POST: RequestHandler = async (event) => {
|
|
|
11
11
|
try {
|
|
12
12
|
switch (slug) {
|
|
13
13
|
case 'logout':
|
|
14
|
-
if (event.locals.user) {
|
|
15
|
-
// if user is null, they are logged out anyway (session might have ended)
|
|
14
|
+
if (event.locals.user) { // else they are logged out / session ended
|
|
16
15
|
sql = `CALL delete_session($1);`
|
|
17
16
|
result = await query(sql, [event.locals.user.id])
|
|
18
17
|
}
|
|
@@ -50,7 +49,7 @@ export const POST: RequestHandler = async (event) => {
|
|
|
50
49
|
// includes when a user tries to register an existing email account with wrong password
|
|
51
50
|
throw error(authenticationResult.statusCode, authenticationResult.status)
|
|
52
51
|
|
|
53
|
-
// Ensures hooks.ts:handle() will not delete cookie
|
|
52
|
+
// Ensures hooks.server.ts:handle() will not delete session cookie
|
|
54
53
|
event.locals.user = authenticationResult.user
|
|
55
54
|
|
|
56
55
|
return json(
|
|
@@ -2,8 +2,8 @@ import type { RequestHandler } from './$types'
|
|
|
2
2
|
import { JWT_SECRET, DOMAIN } from '$env/static/private'
|
|
3
3
|
import type { Secret } from 'jsonwebtoken'
|
|
4
4
|
import jwt from 'jsonwebtoken'
|
|
5
|
-
import { query } from '
|
|
6
|
-
import { sendMessage } from '
|
|
5
|
+
import { query } from '$lib/server/db'
|
|
6
|
+
import { sendMessage } from '$lib/server/send-in-blue'
|
|
7
7
|
|
|
8
8
|
export const POST: RequestHandler = async event => {
|
|
9
9
|
const body = await event.request.json()
|
|
@@ -20,7 +20,6 @@ export const POST: RequestHandler = async event => {
|
|
|
20
20
|
|
|
21
21
|
// Email URL with token to user
|
|
22
22
|
const message: Message = {
|
|
23
|
-
// sender: JSON.parse(<string> VITE_EMAIL_FROM),
|
|
24
23
|
to: [{ email: body.email }],
|
|
25
24
|
subject: 'Password reset',
|
|
26
25
|
tags: ['account'],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { error, json } from '@sveltejs/kit'
|
|
2
2
|
import type { RequestHandler } from './$types'
|
|
3
3
|
import { OAuth2Client } from 'google-auth-library'
|
|
4
|
-
import { query } from '
|
|
4
|
+
import { query } from '$lib/server/db'
|
|
5
5
|
import { PUBLIC_GOOGLE_CLIENT_ID } from '$env/static/public'
|
|
6
6
|
|
|
7
7
|
// Verify JWT per https://developers.google.com/identity/gsi/web/guides/verify-google-id-token
|
|
@@ -47,7 +47,7 @@ export const POST: RequestHandler = async event => {
|
|
|
47
47
|
const user = await getGoogleUserFromJWT(token)
|
|
48
48
|
const userSession = await upsertGoogleUser(user)
|
|
49
49
|
|
|
50
|
-
// Prevent hooks.ts's handler() from deleting cookie thinking no one has authenticated
|
|
50
|
+
// Prevent hooks.server.ts's handler() from deleting cookie thinking no one has authenticated
|
|
51
51
|
event.locals.user = userSession.user
|
|
52
52
|
|
|
53
53
|
return json({
|
|
@@ -2,8 +2,8 @@ import { json } from '@sveltejs/kit'
|
|
|
2
2
|
import type { RequestHandler } from './$types'
|
|
3
3
|
import type { JwtPayload } from 'jsonwebtoken'
|
|
4
4
|
import jwt from 'jsonwebtoken'
|
|
5
|
-
import { query } from '../../_db'
|
|
6
5
|
import { JWT_SECRET } from '$env/static/private'
|
|
6
|
+
import { query } from '$lib/server/db'
|
|
7
7
|
|
|
8
8
|
export const PUT: RequestHandler = async (event) => {
|
|
9
9
|
const body = await event.request.json()
|