@asgardeo/nextjs 0.0.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.
Files changed (62) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +87 -0
  3. package/dist/AsgardeoNextClient.d.ts +40 -0
  4. package/dist/AsgardeoNextClient.js +138 -0
  5. package/dist/AsgardeoNextClient.js.map +1 -0
  6. package/dist/cjs/index.js +67 -0
  7. package/dist/cjs/index.js.map +7 -0
  8. package/dist/client/components/actions/SignInButton.d.ts +41 -0
  9. package/dist/client/components/actions/SignInButton.js +42 -0
  10. package/dist/client/components/actions/SignInButton.js.map +1 -0
  11. package/dist/client/components/actions/SignOutButton.d.ts +41 -0
  12. package/dist/client/components/actions/SignOutButton.js +42 -0
  13. package/dist/client/components/actions/SignOutButton.js.map +1 -0
  14. package/dist/client/components/actions/SignUpButton.d.ts +41 -0
  15. package/dist/client/components/actions/SignUpButton.js +42 -0
  16. package/dist/client/components/actions/SignUpButton.js.map +1 -0
  17. package/dist/client/components/control/SignedIn.d.ts +45 -0
  18. package/dist/client/components/control/SignedIn.js +56 -0
  19. package/dist/client/components/control/SignedIn.js.map +1 -0
  20. package/dist/client/components/control/SignedOut.d.ts +45 -0
  21. package/dist/client/components/control/SignedOut.js +56 -0
  22. package/dist/client/components/control/SignedOut.js.map +1 -0
  23. package/dist/client/contexts/AsgardeoContext.d.ts +28 -0
  24. package/dist/client/contexts/AsgardeoContext.js +26 -0
  25. package/dist/client/contexts/AsgardeoContext.js.map +1 -0
  26. package/dist/client/hooks/useAsgardeo.d.ts +20 -0
  27. package/dist/client/hooks/useAsgardeo.js +29 -0
  28. package/dist/client/hooks/useAsgardeo.js.map +1 -0
  29. package/dist/client/providers/AsgardeoProvider.d.ts +24 -0
  30. package/dist/client/providers/AsgardeoProvider.js +23 -0
  31. package/dist/client/providers/AsgardeoProvider.js.map +1 -0
  32. package/dist/configs/InternalAuthAPIRoutesConfig.d.ts +20 -0
  33. package/dist/configs/InternalAuthAPIRoutesConfig.js +25 -0
  34. package/dist/configs/InternalAuthAPIRoutesConfig.js.map +1 -0
  35. package/dist/index.d.ts +31 -0
  36. package/dist/index.js +29 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/models/api.d.ts +43 -0
  39. package/dist/models/api.js +19 -0
  40. package/dist/models/api.js.map +1 -0
  41. package/dist/models/config.d.ts +30 -0
  42. package/dist/models/config.js +19 -0
  43. package/dist/models/config.js.map +1 -0
  44. package/dist/server/AsgardeoProvider.d.ts +40 -0
  45. package/dist/server/AsgardeoProvider.js +20 -0
  46. package/dist/server/AsgardeoProvider.js.map +1 -0
  47. package/dist/server/actions/deleteSessionId.d.ts +19 -0
  48. package/dist/server/actions/deleteSessionId.js +26 -0
  49. package/dist/server/actions/deleteSessionId.js.map +1 -0
  50. package/dist/server/actions/getSessionId.d.ts +19 -0
  51. package/dist/server/actions/getSessionId.js +26 -0
  52. package/dist/server/actions/getSessionId.js.map +1 -0
  53. package/dist/server/actions/isSignedIn.d.ts +19 -0
  54. package/dist/server/actions/isSignedIn.js +26 -0
  55. package/dist/server/actions/isSignedIn.js.map +1 -0
  56. package/dist/server/actions/setSessionId.d.ts +19 -0
  57. package/dist/server/actions/setSessionId.js +43 -0
  58. package/dist/server/actions/setSessionId.js.map +1 -0
  59. package/dist/utils/decorateConfigWithNextEnv.d.ts +20 -0
  60. package/dist/utils/decorateConfigWithNextEnv.js +28 -0
  61. package/dist/utils/decorateConfigWithNextEnv.js.map +1 -0
  62. package/package.json +70 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ <p align="center" style="color: #343a40">
2
+ <h1 align="center">@asgardeo/nextjs</h1>
3
+ </p>
4
+ <p align="center" style="font-size: 1.2rem;">Next.js SDK for Asgardeo</p>
5
+ <div align="center">
6
+ <img alt="npm (scoped)" src="https://img.shields.io/npm/v/@asgardeo/nextjs">
7
+ <img alt="npm" src="https://img.shields.io/npm/dw/@asgardeo/nextjs">
8
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a>
9
+ </div>
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ # Using npm
15
+ npm install @asgardeo/nextjs
16
+
17
+ # or using pnpm
18
+ pnpm add @asgardeo/nextjs
19
+
20
+ # or using yarn
21
+ yarn add @asgardeo/nextjs
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ 1. Create a `.env.local` file with your Asgardeo configuration:
27
+
28
+ ```bash
29
+ NEXT_PUBLIC_ASGARDEO_BASE_URL=https://api.asgardeo.io/t/<your-org-name>
30
+ NEXT_PUBLIC_ASGARDEO_CLIENT_ID=<your-client-id>
31
+ NEXT_PUBLIC_ASGARDEO_CLIENT_SECRET=<your-client-secret>
32
+ ```
33
+
34
+ 2. Then create a `middleware.ts` file in your project root to handle authentication:
35
+
36
+ ```typescript
37
+ import { AsgardeoNext } from '@asgardeo/nextjs';
38
+ import { NextRequest } from 'next/server';
39
+
40
+ const asgardeo = new AsgardeoNext();
41
+
42
+ asgardeo.initialize({
43
+ baseUrl: process.env.NEXT_PUBLIC_ASGARDEO_BASE_URL,
44
+ clientId: process.env.NEXT_PUBLIC_ASGARDEO_CLIENT_ID,
45
+ clientSecret: process.env.NEXT_PUBLIC_ASGARDEO_CLIENT_SECRET,
46
+ afterSignInUrl: 'http://localhost:3000',
47
+ });
48
+
49
+ export async function middleware(request: NextRequest) {
50
+ return await asgardeo.middleware(request);
51
+ }
52
+
53
+ export const config = {
54
+ matcher: [
55
+ '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
56
+ '/(api|trpc)(.*)',
57
+ ],
58
+ };
59
+ ```
60
+
61
+ 3. Add `SignInButton` and `SignOutButton` buttons to your app
62
+
63
+ ```tsx
64
+ import styles from './page.module.css';
65
+ import {SignInButton, SignedIn, SignOutButton, SignedOut} from '@asgardeo/nextjs';
66
+
67
+ export default function Home() {
68
+ return (
69
+ <div className={styles.page}>
70
+ <main className={styles.main}>
71
+ <div className={styles.ctas}>
72
+ <SignedOut>
73
+ <SignInButton className={styles.primary}>Sign In</SignInButton>
74
+ </SignedOut>
75
+ <SignedIn>
76
+ <SignOutButton className={styles.secondary}>Sign Out</SignOutButton>
77
+ </SignedIn>
78
+ </div>
79
+ </main>
80
+ </div>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ## License
86
+
87
+ Apache-2.0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { AsgardeoNodeClient, SignInOptions, SignOutOptions, User } from '@asgardeo/node';
19
+ import { NextRequest, NextResponse } from 'next/server';
20
+ import { AsgardeoNextConfig } from './models/config';
21
+ /**
22
+ * Client for mplementing Asgardeo in Next.js applications.
23
+ * This class provides the core functionality for managing user authentication and sessions.
24
+ *
25
+ * @typeParam T - Configuration type that extends AsgardeoNextConfig.
26
+ */
27
+ declare class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> extends AsgardeoNodeClient<T> {
28
+ private asgardeo;
29
+ constructor();
30
+ initialize(config: T): Promise<boolean>;
31
+ getUser(): Promise<User>;
32
+ isLoading(): boolean;
33
+ isSignedIn(sessionId?: string): Promise<boolean>;
34
+ signIn(options?: SignInOptions, sessionId?: string, beforeSignIn?: (redirectUrl: string) => NextResponse, authorizationCode?: string, sessionState?: string, state?: string): Promise<User>;
35
+ signOut(options?: SignOutOptions, afterSignOut?: (redirectUrl: string) => void): Promise<string>;
36
+ signOut(options?: SignOutOptions, sessionId?: string, afterSignOut?: (redirectUrl: string) => void): Promise<string>;
37
+ handler(req: NextRequest): Promise<NextResponse>;
38
+ middleware(req: NextRequest): Promise<NextResponse>;
39
+ }
40
+ export default AsgardeoNextClient;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { AsgardeoNodeClient, LegacyAsgardeoNodeClient,
19
+ // removeTrailingSlash,
20
+ } from '@asgardeo/node';
21
+ import { NextResponse } from 'next/server';
22
+ import deleteSessionId from './server/actions/deleteSessionId';
23
+ import getSessionId from './server/actions/getSessionId';
24
+ import setSessionId from './server/actions/setSessionId';
25
+ import decorateConfigWithNextEnv from './utils/decorateConfigWithNextEnv';
26
+ import InternalAuthAPIRoutesConfig from './configs/InternalAuthAPIRoutesConfig';
27
+ const removeTrailingSlash = (path) => (path.endsWith('/') ? path.slice(0, -1) : path);
28
+ /**
29
+ * Client for mplementing Asgardeo in Next.js applications.
30
+ * This class provides the core functionality for managing user authentication and sessions.
31
+ *
32
+ * @typeParam T - Configuration type that extends AsgardeoNextConfig.
33
+ */
34
+ class AsgardeoNextClient extends AsgardeoNodeClient {
35
+ asgardeo;
36
+ constructor() {
37
+ super();
38
+ this.asgardeo = new LegacyAsgardeoNodeClient();
39
+ }
40
+ initialize(config) {
41
+ const { baseUrl, clientId, clientSecret, afterSignInUrl } = decorateConfigWithNextEnv({
42
+ afterSignInUrl: config.afterSignInUrl,
43
+ baseUrl: config.baseUrl,
44
+ clientId: config.clientId,
45
+ clientSecret: config.clientSecret,
46
+ });
47
+ return this.asgardeo.initialize({
48
+ baseUrl,
49
+ clientID: clientId,
50
+ clientSecret,
51
+ signInRedirectURL: afterSignInUrl,
52
+ });
53
+ }
54
+ getUser() {
55
+ throw new Error('Method not implemented.');
56
+ }
57
+ isLoading() {
58
+ return false;
59
+ }
60
+ isSignedIn(sessionId) {
61
+ return this.asgardeo.isAuthenticated(sessionId);
62
+ }
63
+ async signIn(options, sessionId, beforeSignIn, authorizationCode, sessionState, state) {
64
+ let resolvedSessionId = sessionId || (await getSessionId());
65
+ if (!resolvedSessionId) {
66
+ resolvedSessionId = await setSessionId(sessionId);
67
+ }
68
+ return this.asgardeo.signIn(beforeSignIn, resolvedSessionId, authorizationCode, sessionState, state);
69
+ }
70
+ async signOut(...args) {
71
+ if (args[1] && typeof args[1] !== 'string') {
72
+ throw new Error('The second argument must be a string.');
73
+ }
74
+ const resolvedSessionId = args[1] || (await getSessionId());
75
+ return Promise.resolve(await this.asgardeo.signOut(resolvedSessionId));
76
+ }
77
+ async handler(req) {
78
+ const { pathname, searchParams } = req.nextUrl;
79
+ const sanitizedPathname = removeTrailingSlash(pathname);
80
+ const { method } = req;
81
+ if ((method === 'GET' && sanitizedPathname === InternalAuthAPIRoutesConfig.signIn) || searchParams.get('code')) {
82
+ let response;
83
+ await this.signIn({}, undefined, (redirectUrl) => {
84
+ return response = NextResponse.redirect(redirectUrl, 302);
85
+ }, searchParams.get('code'), searchParams.get('session_state'), searchParams.get('state'));
86
+ // If we already redirected via the callback, return that
87
+ if (response) {
88
+ return response;
89
+ }
90
+ if (searchParams.get('code')) {
91
+ const cleanUrl = new URL(req.url);
92
+ cleanUrl.searchParams.delete('code');
93
+ cleanUrl.searchParams.delete('state');
94
+ cleanUrl.searchParams.delete('session_state');
95
+ return NextResponse.redirect(cleanUrl.toString());
96
+ }
97
+ return NextResponse.next();
98
+ }
99
+ if (method === 'GET' && sanitizedPathname === InternalAuthAPIRoutesConfig.session) {
100
+ try {
101
+ const isAuthenticated = await this.isSignedIn();
102
+ return NextResponse.json({ isSignedIn: isAuthenticated });
103
+ }
104
+ catch (error) {
105
+ return NextResponse.json({ error: 'Failed to check session' }, { status: 500 });
106
+ }
107
+ }
108
+ if (method === 'GET' && sanitizedPathname === InternalAuthAPIRoutesConfig.signOut) {
109
+ try {
110
+ const afterSignOutUrl = await this.signOut();
111
+ await deleteSessionId();
112
+ return NextResponse.redirect(afterSignOutUrl, 302);
113
+ }
114
+ catch (error) {
115
+ console.error('[AsgardeoNextClient] Sign-out failed:', error);
116
+ return NextResponse.json({ error: 'Failed to sign out' }, { status: 500 });
117
+ }
118
+ }
119
+ // no auth handler found, simply touch the sessions
120
+ // TODO: this should only happen if rolling sessions are enabled. Also, we should
121
+ // try to avoid reading from the DB (for stateful sessions) on every request if possible.
122
+ // const res = NextResponse.next();
123
+ // const session = await this.sessionStore.get(req.cookies);
124
+ // if (session) {
125
+ // // we pass the existing session (containing an `createdAt` timestamp) to the set method
126
+ // // which will update the cookie's `maxAge` property based on the `createdAt` time
127
+ // await this.sessionStore.set(req.cookies, res.cookies, {
128
+ // ...session,
129
+ // });
130
+ // }
131
+ return NextResponse.next();
132
+ }
133
+ middleware(req) {
134
+ return this.handler(req);
135
+ }
136
+ }
137
+ export default AsgardeoNextClient;
138
+ //# sourceMappingURL=AsgardeoNextClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsgardeoNextClient.js","sourceRoot":"","sources":["../src/AsgardeoNextClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,kBAAk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AC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,YAAY,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,yBAAyB,EAAC,EAAE,EAAC,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;QAED,IAAI,MAAM,KAAK,KAAK,IAAI,iBAAiB,KAAK,2BAA2B,CAAC,OAAO,EAAE,CAAC;YAClF,IAAI,CAAC;gBACH,MAAM,eAAe,GAAW,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBAErD,MAAM,eAAe,EAAE,CAAC;gBAExB,OAAO,YAAY,CAAC,QAAQ,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;gBAC9D,OAAO,YAAY,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,oBAAoB,EAAC,EAAE,EAAC,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QAED,mDAAmD;QACnD,iFAAiF;QACjF,yFAAyF;QACzF,mCAAmC;QACnC,4DAA4D;QAE5D,iBAAiB;QACjB,4FAA4F;QAC5F,sFAAsF;QACtF,4DAA4D;QAC5D,kBAAkB;QAClB,QAAQ;QACR,IAAI;QAEJ,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,GAAgB;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ AsgardeoContext: () => import_AsgardeoContext.default,
33
+ AsgardeoNext: () => import_AsgardeoNextClient.default,
34
+ AsgardeoProvider: () => import_AsgardeoProvider.default,
35
+ SignInButton: () => import_SignInButton.default,
36
+ SignOutButton: () => import_SignOutButton.default,
37
+ SignedIn: () => import_SignedIn.default,
38
+ SignedOut: () => import_SignedOut.default,
39
+ isSignedIn: () => import_isSignedIn.default
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+ var import_AsgardeoProvider = __toESM(require("./server/AsgardeoProvider"), 1);
43
+ __reExport(index_exports, require("./server/AsgardeoProvider"), module.exports);
44
+ var import_isSignedIn = __toESM(require("./server/actions/isSignedIn"), 1);
45
+ var import_SignedIn = __toESM(require("./client/components/control/SignedIn"), 1);
46
+ __reExport(index_exports, require("./client/components/control/SignedIn"), module.exports);
47
+ var import_SignedOut = __toESM(require("./client/components/control/SignedOut"), 1);
48
+ __reExport(index_exports, require("./client/components/control/SignedOut"), module.exports);
49
+ var import_SignInButton = __toESM(require("./client/components/actions/SignInButton"), 1);
50
+ var import_SignOutButton = __toESM(require("./client/components/actions/SignOutButton"), 1);
51
+ var import_AsgardeoContext = __toESM(require("./client/contexts/AsgardeoContext"), 1);
52
+ var import_AsgardeoNextClient = __toESM(require("./AsgardeoNextClient"), 1);
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ AsgardeoContext,
56
+ AsgardeoNext,
57
+ AsgardeoProvider,
58
+ SignInButton,
59
+ SignOutButton,
60
+ SignedIn,
61
+ SignedOut,
62
+ isSignedIn,
63
+ ...require("./server/AsgardeoProvider"),
64
+ ...require("./client/components/control/SignedIn"),
65
+ ...require("./client/components/control/SignedOut")
66
+ });
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport {default as AsgardeoProvider} from './server/AsgardeoProvider';\nexport * from './server/AsgardeoProvider';\n\nexport {default as isSignedIn} from './server/actions/isSignedIn';\n\nexport {default as SignedIn} from './client/components/control/SignedIn';\nexport * from './client/components/control/SignedIn';\n\nexport {default as SignedOut} from './client/components/control/SignedOut';\nexport * from './client/components/control/SignedOut';\n\nexport {default as SignInButton} from './client/components/actions/SignInButton';\nexport type {SignInButtonProps} from './client/components/actions/SignInButton';\n\nexport {default as SignOutButton} from './client/components/actions/SignOutButton';\nexport type {SignOutButtonProps} from './client/components/actions/SignOutButton';\n\nexport {default as AsgardeoContext} from './client/contexts/AsgardeoContext';\nexport type {AsgardeoContextProps} from './client/contexts/AsgardeoContext';\n\nexport {default as AsgardeoNext} from './AsgardeoNextClient';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,8BAA0C;AAC1C,0BAAc,sCAnBd;AAqBA,wBAAoC;AAEpC,sBAAkC;AAClC,0BAAc,iDAxBd;AA0BA,uBAAmC;AACnC,0BAAc,kDA3Bd;AA6BA,0BAAsC;AAGtC,2BAAuC;AAGvC,6BAAyC;AAGzC,gCAAsC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { FC, HTMLAttributes, PropsWithChildren } from 'react';
19
+ /**
20
+ * Props interface of {@link SignInButton}
21
+ */
22
+ export type SignInButtonProps = HTMLAttributes<HTMLButtonElement>;
23
+ /**
24
+ * SignInButton component. This button initiates the sign-in process when clicked.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { SignInButton } from '@asgardeo/auth-react';
29
+ *
30
+ * const App = () => {
31
+ * const buttonRef = useRef<HTMLButtonElement>(null);
32
+ * return (
33
+ * <SignInButton ref={buttonRef} className="custom-class" style={{ backgroundColor: 'blue' }}>
34
+ * Sign In
35
+ * </SignInButton>
36
+ * );
37
+ * }
38
+ * ```
39
+ */
40
+ declare const SignInButton: FC<PropsWithChildren<SignInButtonProps>>;
41
+ export default SignInButton;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ 'use client';
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ import { forwardRef } from 'react';
21
+ import InternalAuthAPIRoutesConfig from '../../../configs/InternalAuthAPIRoutesConfig';
22
+ import { BaseSignInButton } from '@asgardeo/react';
23
+ /**
24
+ * SignInButton component. This button initiates the sign-in process when clicked.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { SignInButton } from '@asgardeo/auth-react';
29
+ *
30
+ * const App = () => {
31
+ * const buttonRef = useRef<HTMLButtonElement>(null);
32
+ * return (
33
+ * <SignInButton ref={buttonRef} className="custom-class" style={{ backgroundColor: 'blue' }}>
34
+ * Sign In
35
+ * </SignInButton>
36
+ * );
37
+ * }
38
+ * ```
39
+ */
40
+ const SignInButton = forwardRef(({ children = 'Sign In', className, style, ...rest }, ref) => (_jsx("form", { action: InternalAuthAPIRoutesConfig.signIn, children: _jsx(BaseSignInButton, { className: className, style: style, ref: ref, type: "submit", ...rest, children: children }) })));
41
+ export default SignInButton;
42
+ //# sourceMappingURL=SignInButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignInButton.js","sourceRoot":"","sources":["../../../../src/client/components/actions/SignInButton.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;AAEb,OAAO,EAAK,UAAU,EAAuD,MAAM,OAAO,CAAC;AAC3F,OAAO,2BAA2B,MAAM,8CAA8C,CAAC;AACvF,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAOjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,YAAY,GAA6C,UAAU,CAIvE,CACE,EAAC,QAAQ,GAAG,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,EAAuC,EACvF,GAA2B,EACb,EAAE,CAAC,CACjB,eAAM,MAAM,EAAE,2BAA2B,CAAC,MAAM,YAC9C,KAAC,gBAAgB,IAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAC,QAAQ,KAAK,IAAI,YACnF,QAAQ,GACQ,GACd,CACR,CACF,CAAC;AAEF,eAAe,YAAY,CAAC"}