@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.
@@ -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
- }