@server/next 0.20.8 → 0.20.10
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/index.d.ts +1 -0
- package/package.json +1 -2
- package/readme.md +5 -5
- package/src/auth/NoSession.js +18 -0
- package/src/auth/auth-cookie.test.js +41 -0
- package/src/auth/auth-token.test.js +42 -0
- package/src/auth/auth.js +52 -0
- package/src/auth/index.js +24 -0
- package/src/auth/index.test.js +123 -0
- package/src/auth/logout.js +18 -0
- package/src/auth/providers/email.js +73 -0
- package/src/auth/providers/index.js +3 -0
- package/src/auth/session.js +18 -0
- package/src/auth/user.js +21 -0
- package/src/context/node.js +9 -5
- package/src/context/winter.js +4 -6
- package/src/errors/index.js +14 -0
- package/src/helpers/cookies.test.js +23 -0
- package/src/helpers/createCookies.js +13 -10
- package/src/helpers/index.js +1 -0
- package/src/helpers/parseHeaders.js +15 -0
- package/src/index.js +68 -3
- package/src/index.test.js +24 -30
- package/src/middle/assets.js +12 -0
- package/src/middle/index.js +7 -66
- package/src/parseResponse.js +3 -1
- package/src/reply.js +5 -2
- package/src/router.test.js +21 -22
- package/src/session.test.js +26 -26
- package/src/test/toSucceed.js +64 -0
- package/src/url.test.js +13 -11
- package/src/auth.test.js +0 -78
- package/src/context/findAuth.js +0 -32
- package/src/context/findSession.js +0 -34
package/src/context/findAuth.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ServerError } from "../index.js";
|
|
2
|
-
|
|
3
|
-
export default async function findAuth(ctx) {
|
|
4
|
-
// NO AUTH AT ALL
|
|
5
|
-
// If there's no even auth option, nothing to do
|
|
6
|
-
const store = ctx.options.auth?.store;
|
|
7
|
-
if (!store) return;
|
|
8
|
-
|
|
9
|
-
// AUTHENTICATION IS AVAILABLE
|
|
10
|
-
ctx.auth = {
|
|
11
|
-
type: ctx.options.auth.type,
|
|
12
|
-
providers: ctx.options.auth.providers,
|
|
13
|
-
store,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// If the user is not authenticated, there's no auth to retrieve
|
|
17
|
-
if (!ctx.headers.authorization) return;
|
|
18
|
-
|
|
19
|
-
// AUTHENTICATED REQUEST
|
|
20
|
-
// Check the authentication header
|
|
21
|
-
const [type, id] = ctx.headers.authorization.trim().split(" ");
|
|
22
|
-
if (type.toLowerCase() !== "bearer") {
|
|
23
|
-
throw ServerError.AUTH_INVALID_TYPE({ type });
|
|
24
|
-
}
|
|
25
|
-
if (id.length !== 24) {
|
|
26
|
-
throw ServerError.AUTH_INVALID_TOKEN();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Extend the basics
|
|
30
|
-
ctx.auth.id = id;
|
|
31
|
-
ctx.user = await store.get(id);
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ServerError } from "../index.js";
|
|
2
|
-
|
|
3
|
-
class NoSession {}
|
|
4
|
-
|
|
5
|
-
export default async function findSession(ctx) {
|
|
6
|
-
const store = ctx.options.session?.store;
|
|
7
|
-
|
|
8
|
-
// If there's no store at all, we don't have session available;
|
|
9
|
-
// but that's okay, since it's only a problem if you try to use it
|
|
10
|
-
if (!store) {
|
|
11
|
-
return new Proxy(new NoSession(), {
|
|
12
|
-
get(target, key) {
|
|
13
|
-
if (target[key]) return target[key];
|
|
14
|
-
if (key === "then") return target[key];
|
|
15
|
-
throw ServerError.NO_STORE_READ({ key });
|
|
16
|
-
},
|
|
17
|
-
set(target, key, value) {
|
|
18
|
-
if (target[key] || key === "then") {
|
|
19
|
-
target[key] = value;
|
|
20
|
-
} else {
|
|
21
|
-
throw ServerError.NO_STORE_WRITE({ key });
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// There's a session cookie; use it as the key to get the data
|
|
28
|
-
// from the store
|
|
29
|
-
if (ctx.cookies.session) {
|
|
30
|
-
return (await store.get(ctx.cookies.session)) || {};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return {};
|
|
34
|
-
}
|