@auth/solid-start 0.1.0 → 0.1.1
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/README.MD +2 -2
- package/index.js +1 -32
- package/package.json +4 -9
- package/src/index.ts +1 -35
package/README.MD
CHANGED
|
@@ -27,8 +27,8 @@ AUTH_TRUST_HOST=true
|
|
|
27
27
|
in this example we are using github so make sure to set the following environment variables:
|
|
28
28
|
|
|
29
29
|
```
|
|
30
|
-
GITHUB_ID=
|
|
31
|
-
GITHUB_SECRET=
|
|
30
|
+
GITHUB_ID=your_github_oauth_id
|
|
31
|
+
GITHUB_SECRET=your_github_oauth_secret
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
```ts
|
package/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Auth } from "@auth/core";
|
|
2
|
-
import { parseString, splitCookiesString } from "set-cookie-parser";
|
|
3
|
-
import { serialize } from "cookie";
|
|
4
2
|
const actions = [
|
|
5
3
|
"providers",
|
|
6
4
|
"session",
|
|
@@ -11,23 +9,6 @@ const actions = [
|
|
|
11
9
|
"verify-request",
|
|
12
10
|
"error"
|
|
13
11
|
];
|
|
14
|
-
const getSetCookieCallback = (cook) => {
|
|
15
|
-
if (!cook)
|
|
16
|
-
return;
|
|
17
|
-
const splitCookie = splitCookiesString(cook);
|
|
18
|
-
for (const cookName of [
|
|
19
|
-
"__Secure-next-auth.session-token",
|
|
20
|
-
"next-auth.session-token",
|
|
21
|
-
"next-auth.pkce.code_verifier",
|
|
22
|
-
"__Secure-next-auth.pkce.code_verifier"
|
|
23
|
-
]) {
|
|
24
|
-
const temp = splitCookie.find((e) => e.startsWith(`${cookName}=`));
|
|
25
|
-
if (temp) {
|
|
26
|
-
return parseString(temp);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return parseString(splitCookie?.[0] ?? "");
|
|
30
|
-
};
|
|
31
12
|
function SolidAuthHandler(prefix, authOptions) {
|
|
32
13
|
return async (event) => {
|
|
33
14
|
const { request } = event;
|
|
@@ -36,19 +17,7 @@ function SolidAuthHandler(prefix, authOptions) {
|
|
|
36
17
|
if (!actions.includes(action) || !url.pathname.startsWith(prefix + "/")) {
|
|
37
18
|
return;
|
|
38
19
|
}
|
|
39
|
-
|
|
40
|
-
if (["callback", "signin", "signout"].includes(action)) {
|
|
41
|
-
const parsedCookie = getSetCookieCallback(
|
|
42
|
-
res.clone().headers.get("Set-Cookie")
|
|
43
|
-
);
|
|
44
|
-
if (parsedCookie) {
|
|
45
|
-
res.headers.set(
|
|
46
|
-
"Set-Cookie",
|
|
47
|
-
serialize(parsedCookie.name, parsedCookie.value, parsedCookie)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return res;
|
|
20
|
+
return await Auth(request, authOptions);
|
|
52
21
|
};
|
|
53
22
|
}
|
|
54
23
|
function SolidAuth(config) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/solid-start",
|
|
3
3
|
"description": "Authentication for SolidStart.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"client.*",
|
|
@@ -24,23 +24,18 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@solidjs/meta": "^0.28.0",
|
|
27
|
-
"@types/cookie": "0.5.1",
|
|
28
27
|
"@types/node": "^18.7.14",
|
|
29
|
-
"@types/set-cookie-parser": "^2.4.2",
|
|
30
28
|
"solid-js": "^1.5.7",
|
|
31
|
-
"solid-start": "^0.2.
|
|
29
|
+
"solid-start": "^0.2.14",
|
|
32
30
|
"tsup": "^6.5.0",
|
|
33
31
|
"typescript": "^4.8.2",
|
|
34
|
-
"@auth/core": "0.
|
|
32
|
+
"@auth/core": "0.4.0",
|
|
35
33
|
"next-auth": "4.18.6"
|
|
36
34
|
},
|
|
37
35
|
"peerDependencies": {
|
|
38
36
|
"@auth/core": "~0.2.2 || ^0.2.2",
|
|
39
37
|
"solid-js": "^1.5.7",
|
|
40
|
-
"solid-start": "^0.2.
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"set-cookie-parser": "^2.5.1"
|
|
38
|
+
"solid-start": "^0.2.14"
|
|
44
39
|
},
|
|
45
40
|
"keywords": [
|
|
46
41
|
"SolidJS",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Auth } from "@auth/core"
|
|
2
|
-
import { Cookie, parseString, splitCookiesString } from "set-cookie-parser"
|
|
3
|
-
import { serialize } from "cookie"
|
|
4
2
|
import type { AuthAction, AuthConfig, Session } from "@auth/core/types"
|
|
5
3
|
|
|
6
4
|
export interface SolidAuthConfig extends AuthConfig {
|
|
@@ -22,26 +20,6 @@ const actions: AuthAction[] = [
|
|
|
22
20
|
"error",
|
|
23
21
|
]
|
|
24
22
|
|
|
25
|
-
// currently multiple cookies are not supported, so we keep the next-auth.pkce.code_verifier cookie for now:
|
|
26
|
-
// because it gets updated anyways
|
|
27
|
-
// src: https://github.com/solidjs/solid-start/issues/293
|
|
28
|
-
const getSetCookieCallback = (cook?: string | null): Cookie | undefined => {
|
|
29
|
-
if (!cook) return
|
|
30
|
-
const splitCookie = splitCookiesString(cook)
|
|
31
|
-
for (const cookName of [
|
|
32
|
-
"__Secure-next-auth.session-token",
|
|
33
|
-
"next-auth.session-token",
|
|
34
|
-
"next-auth.pkce.code_verifier",
|
|
35
|
-
"__Secure-next-auth.pkce.code_verifier",
|
|
36
|
-
]) {
|
|
37
|
-
const temp = splitCookie.find((e) => e.startsWith(`${cookName}=`))
|
|
38
|
-
if (temp) {
|
|
39
|
-
return parseString(temp)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return parseString(splitCookie?.[0] ?? "") // just return the first cookie if no session token is found
|
|
43
|
-
}
|
|
44
|
-
|
|
45
23
|
function SolidAuthHandler(prefix: string, authOptions: SolidAuthConfig) {
|
|
46
24
|
return async (event: any) => {
|
|
47
25
|
const { request } = event
|
|
@@ -54,19 +32,7 @@ function SolidAuthHandler(prefix: string, authOptions: SolidAuthConfig) {
|
|
|
54
32
|
return
|
|
55
33
|
}
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
if (["callback", "signin", "signout"].includes(action)) {
|
|
59
|
-
const parsedCookie = getSetCookieCallback(
|
|
60
|
-
res.clone().headers.get("Set-Cookie")
|
|
61
|
-
)
|
|
62
|
-
if (parsedCookie) {
|
|
63
|
-
res.headers.set(
|
|
64
|
-
"Set-Cookie",
|
|
65
|
-
serialize(parsedCookie.name, parsedCookie.value, parsedCookie as any)
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return res
|
|
35
|
+
return await Auth(request, authOptions)
|
|
70
36
|
}
|
|
71
37
|
}
|
|
72
38
|
|