@auth/solid-start 0.1.0 → 0.1.2

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 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=your_github_oatuh_id
31
- GITHUB_SECRET=your_github_oatuh_secret
30
+ GITHUB_ID=your_github_oauth_id
31
+ GITHUB_SECRET=your_github_oauth_secret
32
32
  ```
33
33
 
34
34
  ```ts
package/client.d.ts CHANGED
@@ -1,6 +1,24 @@
1
- import { LiteralUnion, SignInOptions, SignInAuthorizationParams, SignOutParams } from 'next-auth/react';
2
1
  import { RedirectableProviderType, BuiltInProviderType } from '@auth/core/providers';
3
2
 
3
+ type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
4
+ interface SignInOptions extends Record<string, unknown> {
5
+ /**
6
+ * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
7
+ *
8
+ * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
9
+ */
10
+ callbackUrl?: string;
11
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
12
+ redirect?: boolean;
13
+ }
14
+ interface SignOutParams<R extends boolean = true> {
15
+ /** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
16
+ callbackUrl?: string;
17
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
18
+ redirect?: R;
19
+ }
20
+ /** Match `inputType` of `new URLSearchParams(inputType)` */
21
+ type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
4
22
  /**
5
23
  * Client-side method to initiate a signin flow
6
24
  * or send the user to the signin page listing all possible providers.
@@ -17,4 +35,4 @@ declare function signIn<P extends RedirectableProviderType | undefined = undefin
17
35
  */
18
36
  declare function signOut(options?: SignOutParams): Promise<void>;
19
37
 
20
- export { signIn, signOut };
38
+ export { SignInAuthorizationParams, signIn, signOut };
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
- const res = await Auth(request, authOptions);
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.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "client.*",
@@ -24,23 +24,17 @@
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.1",
29
+ "solid-start": "^0.2.14",
32
30
  "tsup": "^6.5.0",
33
- "typescript": "^4.8.2",
34
- "@auth/core": "0.2.3",
35
- "next-auth": "4.18.6"
31
+ "typescript": "5.2.2",
32
+ "@auth/core": "0.16.0"
36
33
  },
37
34
  "peerDependencies": {
38
35
  "@auth/core": "~0.2.2 || ^0.2.2",
39
36
  "solid-js": "^1.5.7",
40
- "solid-start": "^0.2.1"
41
- },
42
- "dependencies": {
43
- "set-cookie-parser": "^2.5.1"
37
+ "solid-start": "^0.2.14"
44
38
  },
45
39
  "keywords": [
46
40
  "SolidJS",
package/src/client.ts CHANGED
@@ -1,14 +1,35 @@
1
- import type {
2
- LiteralUnion,
3
- SignInOptions,
4
- SignInAuthorizationParams,
5
- SignOutParams,
6
- } from "next-auth/react"
7
1
  import type {
8
2
  BuiltInProviderType,
9
3
  RedirectableProviderType,
10
4
  } from "@auth/core/providers"
11
5
 
6
+ type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
7
+
8
+ interface SignInOptions extends Record<string, unknown> {
9
+ /**
10
+ * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
11
+ *
12
+ * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
13
+ */
14
+ callbackUrl?: string
15
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
16
+ redirect?: boolean
17
+ }
18
+
19
+ interface SignOutParams<R extends boolean = true> {
20
+ /** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
21
+ callbackUrl?: string
22
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
23
+ redirect?: R
24
+ }
25
+
26
+ /** Match `inputType` of `new URLSearchParams(inputType)` */
27
+ export type SignInAuthorizationParams =
28
+ | string
29
+ | string[][]
30
+ | Record<string, string>
31
+ | URLSearchParams
32
+
12
33
  /**
13
34
  * Client-side method to initiate a signin flow
14
35
  * or send the user to the signin page listing all possible providers.
@@ -51,7 +72,7 @@ export async function signIn<
51
72
  "Content-Type": "application/x-www-form-urlencoded",
52
73
  "X-Auth-Return-Redirect": "1",
53
74
  },
54
- // @ts-expect-error -- ignore
75
+ // @ts-ignore
55
76
  body: new URLSearchParams({
56
77
  ...options,
57
78
  csrfToken,
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
- const res = await Auth(request, authOptions)
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