@auth/solid-start 0.15.4 → 0.16.0

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
@@ -9,7 +9,7 @@
9
9
  <p align="center">
10
10
  <a href="https://www.npmjs.com/package/@auth/solid-start"><img src="https://img.shields.io/npm/v/@auth/solid-start?style=flat-square&label=latest&color=purple" alt="npm latest release" /></a>
11
11
  <a href="https://www.npmtrends.com/@auth/solid-start"><img src="https://img.shields.io/npm/dm/@auth/solid-start?style=flat-square&color=cyan" alt="Downloads" /></a>
12
- <a href="https://github.com/nextauthjs/next-auth/stargazers"><img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square&color=orange" alt="Github Stars" /></a>
12
+ <a href="https://github.com/nextauthjs/next-auth/stargazers"><img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square&color=orange" alt="GitHub Stars" /></a>
13
13
  <img src="https://shields.io/badge/TypeScript-3178C6?logo=TypeScript&logoColor=fff&style=flat-square" alt="TypeScript" />
14
14
  </p>
15
15
 
package/client.d.ts CHANGED
@@ -1,14 +1,27 @@
1
- import type { BuiltInProviderType, RedirectableProviderType } from "@auth/core/providers";
2
- type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
3
- interface SignInOptions extends Record<string, unknown> {
1
+ import type { ProviderId } from "@auth/core/providers";
2
+ interface SignInOptions<Redirect extends boolean = true> extends Record<string, unknown> {
3
+ /** @deprecated Use `redirectTo` instead. */
4
+ callbackUrl?: string;
4
5
  /**
5
- * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
6
+ * Specify where the user should be redirected to after a successful signin.
6
7
  *
7
- * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
8
+ * By default, it is the page the sign-in was initiated from.
8
9
  */
9
- callbackUrl?: string;
10
- /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
11
- redirect?: boolean;
10
+ redirectTo?: string;
11
+ /**
12
+ * You might want to deal with the signin response on the same page, instead of redirecting to another page.
13
+ * For example, if an error occurs (like wrong credentials given by the user), you might want to show an inline error message on the input field.
14
+ *
15
+ * For this purpose, you can set this to option `redirect: false`.
16
+ */
17
+ redirect?: Redirect;
18
+ }
19
+ export interface SignInResponse {
20
+ error: string | undefined;
21
+ code: string | undefined;
22
+ status: number;
23
+ ok: boolean;
24
+ url: string | null;
12
25
  }
13
26
  interface SignOutParams<R extends boolean = true> {
14
27
  /** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
@@ -29,7 +42,15 @@ export type SignInAuthorizationParams = string | string[][] | Record<string, str
29
42
  * signIn("provider") // example: signIn("github")
30
43
  * ```
31
44
  */
32
- export declare function signIn<P extends RedirectableProviderType | undefined = undefined>(providerId?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions, authorizationParams?: SignInAuthorizationParams): Promise<Response | undefined>;
45
+ /**
46
+ * Initiates a signin flow or sends the user to the signin page listing all possible providers.
47
+ * Handles CSRF protection.
48
+ *
49
+ * @note This method can only be used from Client Components ("use client" or Pages Router).
50
+ * For Server Actions, use the `signIn` method imported from the `auth` config.
51
+ */
52
+ export declare function signIn(provider?: ProviderId, options?: SignInOptions<true>, authorizationParams?: SignInAuthorizationParams): Promise<void>;
53
+ export declare function signIn(provider?: ProviderId, options?: SignInOptions<false>, authorizationParams?: SignInAuthorizationParams): Promise<SignInResponse>;
33
54
  /**
34
55
  * Signs the user out, by removing the session cookie.
35
56
  * Automatically adds the CSRF token to the request.
package/client.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAE7B,KAAK,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,MAAM,IAA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IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,OAAO,CAAA;IACX,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACnB;AAED,UAAU,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,IAAI;IAC9C,kGAAkG;IAClG,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,CAAC,CAAA;CACb;AAED,4DAA4D;AAC5D,MAAM,MAAM,yBAAyB,GACjC,MAAM,GACN,MAAM,EAAE,EAAE,GACV,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,eAAe,CAAA;AAEnB;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,EAC7B,mBAAmB,CAAC,EAAE,yBAAyB,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAA;AAChB,wBAAsB,MAAM,CAC1B,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,EAC9B,mBAAmB,CAAC,EAAE,yBAAyB,GAC9C,OAAO,CAAC,cAAc,CAAC,CAAA;AA4D1B;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAAC,OAAO,CAAC,EAAE,aAAa,iBAsBpD"}
package/client.js CHANGED
@@ -1,50 +1,41 @@
1
- /**
2
- * Client-side method to initiate a signin flow
3
- * or send the user to the signin page listing all possible providers.
4
- * Automatically adds the CSRF token to the request.
5
- *
6
- * ```ts
7
- * import { signIn } from "@auth/solid-start/client"
8
- * signIn()
9
- * signIn("provider") // example: signIn("github")
10
- * ```
11
- */
12
- export async function signIn(providerId, options, authorizationParams) {
13
- const { callbackUrl = window.location.href, redirect = true } = options ?? {};
14
- // TODO: Support custom providers
15
- const isCredentials = providerId === "credentials";
16
- const isEmail = providerId === "email";
17
- const isSupportingReturn = isCredentials || isEmail;
18
- // TODO: Handle custom base path
19
- const signInUrl = `/api/auth/${isCredentials ? "callback" : "signin"}/${providerId}`;
20
- const _signInUrl = `${signInUrl}?${new URLSearchParams(authorizationParams)}`;
1
+ export async function signIn(provider, options, authorizationParams) {
2
+ const { callbackUrl, ...rest } = options ?? {};
3
+ const { redirect = true, redirectTo = callbackUrl ?? window.location.href, ...signInParams } = rest;
4
+ const isCredentials = provider === "credentials";
5
+ const signInUrl = `/api/auth/${isCredentials ? "callback" : "signin"}/${provider}`;
21
6
  // TODO: Handle custom base path
22
7
  const csrfTokenResponse = await fetch("/api/auth/csrf");
23
8
  const { csrfToken } = await csrfTokenResponse.json();
24
- const res = await fetch(_signInUrl, {
9
+ const res = await fetch(`${signInUrl}?${new URLSearchParams(authorizationParams)}`, {
25
10
  method: "post",
26
11
  headers: {
27
12
  "Content-Type": "application/x-www-form-urlencoded",
28
13
  "X-Auth-Return-Redirect": "1",
29
14
  },
30
- // @ts-ignore
31
15
  body: new URLSearchParams({
32
- ...options,
16
+ ...signInParams,
33
17
  csrfToken,
34
- callbackUrl,
18
+ callbackUrl: redirectTo,
35
19
  }),
36
20
  });
37
- const data = await res.clone().json();
38
- const error = new URL(data.url).searchParams.get("error");
39
- if (redirect || !isSupportingReturn || !error) {
40
- // TODO: Do not redirect for Credentials and Email providers by default in next major
41
- window.location.href = data.url ?? data.redirect ?? callbackUrl;
21
+ const data = await res.json();
22
+ if (redirect) {
23
+ const url = data.url ?? redirectTo;
24
+ window.location.href = url;
42
25
  // If url contains a hash, the browser does not reload the page. We reload manually
43
- if (data.url.includes("#"))
26
+ if (url.includes("#"))
44
27
  window.location.reload();
45
28
  return;
46
29
  }
47
- return res;
30
+ const error = new URL(data.url).searchParams.get("error") ?? undefined;
31
+ const code = new URL(data.url).searchParams.get("code") ?? undefined;
32
+ return {
33
+ error,
34
+ code,
35
+ status: res.status,
36
+ ok: res.ok,
37
+ url: error ? null : data.url,
38
+ };
48
39
  }
49
40
  /**
50
41
  * Signs the user out, by removing the session cookie.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth/solid-start",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "description": "Authentication for SolidStart.",
5
5
  "license": "ISC",
6
6
  "author": "OrJDev <orjdeveloper@gmail.com>",
@@ -49,7 +49,7 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@auth/core": "0.37.4"
52
+ "@auth/core": "0.38.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@solidjs/meta": "^0.28.0",
@@ -0,0 +1,3 @@
1
+ export * from "@auth/core/providers/bitbucket";
2
+ export { default } from "@auth/core/providers/bitbucket";
3
+ //# sourceMappingURL=bitbucket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../src/providers/bitbucket.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@auth/core/providers/bitbucket";
2
+ export { default } from "@auth/core/providers/bitbucket";
@@ -0,0 +1,3 @@
1
+ export * from "@auth/core/providers/figma";
2
+ export { default } from "@auth/core/providers/figma";
3
+ //# sourceMappingURL=figma.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"figma.d.ts","sourceRoot":"","sources":["../src/providers/figma.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@auth/core/providers/figma";
2
+ export { default } from "@auth/core/providers/figma";
@@ -0,0 +1,3 @@
1
+ export * from "@auth/core/providers/frontegg";
2
+ export { default } from "@auth/core/providers/frontegg";
3
+ //# sourceMappingURL=frontegg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontegg.d.ts","sourceRoot":"","sources":["../src/providers/frontegg.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@auth/core/providers/frontegg";
2
+ export { default } from "@auth/core/providers/frontegg";
@@ -0,0 +1,3 @@
1
+ export * from "@auth/core/providers/logto";
2
+ export { default } from "@auth/core/providers/logto";
3
+ //# sourceMappingURL=logto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logto.d.ts","sourceRoot":"","sources":["../src/providers/logto.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@auth/core/providers/logto";
2
+ export { default } from "@auth/core/providers/logto";
@@ -0,0 +1,3 @@
1
+ export * from "@auth/core/providers/loops";
2
+ export { default } from "@auth/core/providers/loops";
3
+ //# sourceMappingURL=loops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loops.d.ts","sourceRoot":"","sources":["../src/providers/loops.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "@auth/core/providers/loops";
2
+ export { default } from "@auth/core/providers/loops";
package/src/client.ts CHANGED
@@ -1,19 +1,30 @@
1
- import type {
2
- BuiltInProviderType,
3
- RedirectableProviderType,
4
- } from "@auth/core/providers"
1
+ import type { ProviderId } from "@auth/core/providers"
5
2
 
6
- type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
7
-
8
- interface SignInOptions extends Record<string, unknown> {
3
+ interface SignInOptions<Redirect extends boolean = true>
4
+ extends Record<string, unknown> {
5
+ /** @deprecated Use `redirectTo` instead. */
6
+ callbackUrl?: string
9
7
  /**
10
- * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
8
+ * Specify where the user should be redirected to after a successful signin.
11
9
  *
12
- * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
10
+ * By default, it is the page the sign-in was initiated from.
13
11
  */
14
- callbackUrl?: string
15
- /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
16
- redirect?: boolean
12
+ redirectTo?: string
13
+ /**
14
+ * You might want to deal with the signin response on the same page, instead of redirecting to another page.
15
+ * For example, if an error occurs (like wrong credentials given by the user), you might want to show an inline error message on the input field.
16
+ *
17
+ * For this purpose, you can set this to option `redirect: false`.
18
+ */
19
+ redirect?: Redirect
20
+ }
21
+
22
+ export interface SignInResponse {
23
+ error: string | undefined
24
+ code: string | undefined
25
+ status: number
26
+ ok: boolean
27
+ url: string | null
17
28
  }
18
29
 
19
30
  interface SignOutParams<R extends boolean = true> {
@@ -41,59 +52,81 @@ export type SignInAuthorizationParams =
41
52
  * signIn("provider") // example: signIn("github")
42
53
  * ```
43
54
  */
44
- export async function signIn<
45
- P extends RedirectableProviderType | undefined = undefined,
46
- >(
47
- providerId?: LiteralUnion<
48
- P extends RedirectableProviderType
49
- ? P | BuiltInProviderType
50
- : BuiltInProviderType
51
- >,
52
- options?: SignInOptions,
55
+
56
+ /**
57
+ * Initiates a signin flow or sends the user to the signin page listing all possible providers.
58
+ * Handles CSRF protection.
59
+ *
60
+ * @note This method can only be used from Client Components ("use client" or Pages Router).
61
+ * For Server Actions, use the `signIn` method imported from the `auth` config.
62
+ */
63
+ export async function signIn(
64
+ provider?: ProviderId,
65
+ options?: SignInOptions<true>,
53
66
  authorizationParams?: SignInAuthorizationParams
54
- ) {
55
- const { callbackUrl = window.location.href, redirect = true } = options ?? {}
67
+ ): Promise<void>
68
+ export async function signIn(
69
+ provider?: ProviderId,
70
+ options?: SignInOptions<false>,
71
+ authorizationParams?: SignInAuthorizationParams
72
+ ): Promise<SignInResponse>
73
+ export async function signIn<Redirect extends boolean = true>(
74
+ provider?: ProviderId,
75
+ options?: SignInOptions<Redirect>,
76
+ authorizationParams?: SignInAuthorizationParams
77
+ ): Promise<SignInResponse | void> {
78
+ const { callbackUrl, ...rest } = options ?? {}
79
+ const {
80
+ redirect = true,
81
+ redirectTo = callbackUrl ?? window.location.href,
82
+ ...signInParams
83
+ } = rest
56
84
 
57
- // TODO: Support custom providers
58
- const isCredentials = providerId === "credentials"
59
- const isEmail = providerId === "email"
60
- const isSupportingReturn = isCredentials || isEmail
85
+ const isCredentials = provider === "credentials"
61
86
 
62
- // TODO: Handle custom base path
63
87
  const signInUrl = `/api/auth/${
64
88
  isCredentials ? "callback" : "signin"
65
- }/${providerId}`
66
-
67
- const _signInUrl = `${signInUrl}?${new URLSearchParams(authorizationParams)}`
89
+ }/${provider}`
68
90
 
69
91
  // TODO: Handle custom base path
70
92
  const csrfTokenResponse = await fetch("/api/auth/csrf")
71
93
  const { csrfToken } = await csrfTokenResponse.json()
94
+ const res = await fetch(
95
+ `${signInUrl}?${new URLSearchParams(authorizationParams)}`,
96
+ {
97
+ method: "post",
98
+ headers: {
99
+ "Content-Type": "application/x-www-form-urlencoded",
100
+ "X-Auth-Return-Redirect": "1",
101
+ },
102
+ body: new URLSearchParams({
103
+ ...signInParams,
104
+ csrfToken,
105
+ callbackUrl: redirectTo,
106
+ }),
107
+ }
108
+ )
72
109
 
73
- const res = await fetch(_signInUrl, {
74
- method: "post",
75
- headers: {
76
- "Content-Type": "application/x-www-form-urlencoded",
77
- "X-Auth-Return-Redirect": "1",
78
- },
79
- // @ts-ignore
80
- body: new URLSearchParams({
81
- ...options,
82
- csrfToken,
83
- callbackUrl,
84
- }),
85
- })
110
+ const data = await res.json()
86
111
 
87
- const data = await res.clone().json()
88
- const error = new URL(data.url).searchParams.get("error")
89
- if (redirect || !isSupportingReturn || !error) {
90
- // TODO: Do not redirect for Credentials and Email providers by default in next major
91
- window.location.href = data.url ?? data.redirect ?? callbackUrl
112
+ if (redirect) {
113
+ const url = data.url ?? redirectTo
114
+ window.location.href = url
92
115
  // If url contains a hash, the browser does not reload the page. We reload manually
93
- if (data.url.includes("#")) window.location.reload()
116
+ if (url.includes("#")) window.location.reload()
94
117
  return
95
118
  }
96
- return res
119
+
120
+ const error = new URL(data.url).searchParams.get("error") ?? undefined
121
+ const code = new URL(data.url).searchParams.get("code") ?? undefined
122
+
123
+ return {
124
+ error,
125
+ code,
126
+ status: res.status,
127
+ ok: res.ok,
128
+ url: error ? null : data.url,
129
+ }
97
130
  }
98
131
 
99
132
  /**