@asgardeo/nextjs 0.0.2 → 0.1.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.
Files changed (76) hide show
  1. package/README.md +68 -8
  2. package/dist/AsgardeoNextClient.d.ts +44 -9
  3. package/dist/AsgardeoNextClient.js +178 -85
  4. package/dist/AsgardeoNextClient.js.map +1 -1
  5. package/dist/cjs/index.js +28 -2
  6. package/dist/cjs/index.js.map +2 -2
  7. package/dist/client/components/actions/SignInButton/SignInButton.d.ts +2 -2
  8. package/dist/client/components/actions/SignInButton/SignInButton.js +34 -7
  9. package/dist/client/components/actions/SignInButton/SignInButton.js.map +1 -1
  10. package/dist/client/components/actions/SignOutButton/SignOutButton.d.ts +1 -2
  11. package/dist/client/components/actions/SignOutButton/SignOutButton.js +25 -4
  12. package/dist/client/components/actions/SignOutButton/SignOutButton.js.map +1 -1
  13. package/dist/client/components/actions/SignUpButton/SignUpButton.d.ts +38 -14
  14. package/dist/client/components/actions/SignUpButton/SignUpButton.js +69 -15
  15. package/dist/client/components/actions/SignUpButton/SignUpButton.js.map +1 -1
  16. package/dist/client/components/control/SignedIn/SignedIn.js +3 -17
  17. package/dist/client/components/control/SignedIn/SignedIn.js.map +1 -1
  18. package/dist/client/components/control/SignedOut/SignedOut.js +3 -17
  19. package/dist/client/components/control/SignedOut/SignedOut.js.map +1 -1
  20. package/dist/client/components/presentation/SignIn/SignIn.d.ts +69 -0
  21. package/dist/client/components/presentation/SignIn/SignIn.js +85 -0
  22. package/dist/client/components/presentation/SignIn/SignIn.js.map +1 -0
  23. package/dist/client/components/presentation/SignUp/SignUp.d.ts +55 -0
  24. package/dist/client/components/presentation/SignUp/SignUp.js +70 -0
  25. package/dist/client/components/presentation/SignUp/SignUp.js.map +1 -0
  26. package/dist/client/components/presentation/UserDropdown/UserDropdown.d.ts +105 -0
  27. package/dist/client/components/presentation/UserDropdown/UserDropdown.js +106 -0
  28. package/dist/client/components/presentation/UserDropdown/UserDropdown.js.map +1 -0
  29. package/dist/client/components/presentation/UserProfile/UserProfile.d.ts +49 -0
  30. package/dist/client/components/presentation/UserProfile/UserProfile.js +57 -0
  31. package/dist/client/components/presentation/UserProfile/UserProfile.js.map +1 -0
  32. package/dist/client/contexts/Asgardeo/AsgardeoContext.d.ts +1 -8
  33. package/dist/client/contexts/Asgardeo/AsgardeoContext.js +13 -1
  34. package/dist/client/contexts/Asgardeo/AsgardeoContext.js.map +1 -1
  35. package/dist/client/contexts/Asgardeo/AsgardeoProvider.d.ts +15 -5
  36. package/dist/client/contexts/Asgardeo/AsgardeoProvider.js +119 -37
  37. package/dist/client/contexts/Asgardeo/AsgardeoProvider.js.map +1 -1
  38. package/dist/index.d.ts +14 -0
  39. package/dist/index.js +9 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/middleware/asgardeoMiddleware.d.ts +63 -0
  42. package/dist/middleware/asgardeoMiddleware.js +115 -0
  43. package/dist/middleware/asgardeoMiddleware.js.map +1 -0
  44. package/dist/server/AsgardeoProvider.d.ts +6 -3
  45. package/dist/server/AsgardeoProvider.js +42 -3
  46. package/dist/server/AsgardeoProvider.js.map +1 -1
  47. package/dist/server/actions/getClientOrigin.d.ts +2 -0
  48. package/dist/server/actions/getClientOrigin.js +10 -0
  49. package/dist/server/actions/getClientOrigin.js.map +1 -0
  50. package/dist/server/actions/getUserAction.d.ts +35 -0
  51. package/dist/server/actions/getUserAction.js +35 -0
  52. package/dist/server/actions/getUserAction.js.map +1 -0
  53. package/dist/server/actions/getUserProfileAction.d.ts +40 -0
  54. package/dist/server/actions/getUserProfileAction.js +45 -0
  55. package/dist/server/actions/getUserProfileAction.js.map +1 -0
  56. package/dist/server/actions/handleOAuthCallbackAction.d.ts +33 -0
  57. package/dist/server/actions/handleOAuthCallbackAction.js +80 -0
  58. package/dist/server/actions/handleOAuthCallbackAction.js.map +1 -0
  59. package/dist/server/actions/isSignedIn.d.ts +1 -1
  60. package/dist/server/actions/isSignedIn.js +5 -5
  61. package/dist/server/actions/isSignedIn.js.map +1 -1
  62. package/dist/server/actions/signInAction.d.ts +35 -0
  63. package/dist/server/actions/signInAction.js +71 -0
  64. package/dist/server/actions/signInAction.js.map +1 -0
  65. package/dist/server/actions/signOutAction.d.ts +25 -0
  66. package/dist/server/actions/signOutAction.js +33 -0
  67. package/dist/server/actions/signOutAction.js.map +1 -0
  68. package/dist/server/actions/signUpAction.d.ts +35 -0
  69. package/dist/server/actions/signUpAction.js +52 -0
  70. package/dist/server/actions/signUpAction.js.map +1 -0
  71. package/dist/server/actions/updateUserProfileAction.d.ts +36 -0
  72. package/dist/server/actions/updateUserProfileAction.js +41 -0
  73. package/dist/server/actions/updateUserProfileAction.js.map +1 -0
  74. package/dist/utils/decorateConfigWithNextEnv.js +5 -1
  75. package/dist/utils/decorateConfigWithNextEnv.js.map +1 -1
  76. package/package.json +14 -4
@@ -0,0 +1,80 @@
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 server';
19
+ import { cookies } from 'next/headers';
20
+ import { CookieConfig } from '@asgardeo/node';
21
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
22
+ /**
23
+ * Server action to handle OAuth callback with authorization code.
24
+ * This action processes the authorization code received from the OAuth provider
25
+ * and exchanges it for tokens to complete the authentication flow.
26
+ *
27
+ * @param code - Authorization code from OAuth provider
28
+ * @param state - State parameter from OAuth provider for CSRF protection
29
+ * @param sessionState - Session state parameter from OAuth provider
30
+ * @returns Promise that resolves with success status and optional error message
31
+ */
32
+ const handleOAuthCallbackAction = async (code, state, sessionState) => {
33
+ try {
34
+ if (!code || !state) {
35
+ return {
36
+ success: false,
37
+ error: 'Missing required OAuth parameters: code and state are required'
38
+ };
39
+ }
40
+ // Get the Asgardeo client instance
41
+ const asgardeoClient = AsgardeoNextClient.getInstance();
42
+ if (!asgardeoClient.isInitialized) {
43
+ return {
44
+ success: false,
45
+ error: 'Asgardeo client is not initialized'
46
+ };
47
+ }
48
+ // Get the session ID from cookies
49
+ const cookieStore = await cookies();
50
+ const sessionId = cookieStore.get(CookieConfig.SESSION_COOKIE_NAME)?.value;
51
+ if (!sessionId) {
52
+ return {
53
+ success: false,
54
+ error: 'No session found. Please start the authentication flow again.'
55
+ };
56
+ }
57
+ // Exchange the authorization code for tokens
58
+ await asgardeoClient.signIn({
59
+ code,
60
+ session_state: sessionState,
61
+ state,
62
+ }, {}, sessionId);
63
+ // Get the after sign-in URL from configuration
64
+ const config = await asgardeoClient.getConfiguration();
65
+ const afterSignInUrl = config.afterSignInUrl || '/';
66
+ return {
67
+ success: true,
68
+ redirectUrl: afterSignInUrl
69
+ };
70
+ }
71
+ catch (error) {
72
+ console.error('[handleOAuthCallbackAction] OAuth callback error:', error);
73
+ return {
74
+ success: false,
75
+ error: error instanceof Error ? error.message : 'Authentication failed'
76
+ };
77
+ }
78
+ };
79
+ export default handleOAuthCallbackAction;
80
+ //# sourceMappingURL=handleOAuthCallbackAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleOAuthCallbackAction.js","sourceRoot":"","sources":["../../../src/server/actions/handleOAuthCallbackAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,kBAAkB,MAAM,0BAA0B,CAAC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,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;SACxE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
@@ -15,5 +15,5 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- declare const isSignedIn: () => Promise<boolean>;
18
+ declare const isSignedIn: (sessionId: string) => Promise<boolean>;
19
19
  export default isSignedIn;
@@ -16,11 +16,11 @@
16
16
  * under the License.
17
17
  */
18
18
  'use server';
19
- import { CookieConfig } from '@asgardeo/node';
20
- import { cookies } from 'next/headers';
21
- const isSignedIn = async () => {
22
- const cookieStore = await cookies();
23
- return !!cookieStore.get(CookieConfig.SESSION_COOKIE_NAME)?.value;
19
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
20
+ const isSignedIn = async (sessionId) => {
21
+ const client = AsgardeoNextClient.getInstance();
22
+ const accessToken = await client.getAccessToken(sessionId);
23
+ return !!accessToken;
24
24
  };
25
25
  export default isSignedIn;
26
26
  //# sourceMappingURL=isSignedIn.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isSignedIn.js","sourceRoot":"","sources":["../../../src/server/actions/isSignedIn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,MAAM,UAAU,GAAG,KAAK,IAAsB,EAAE;IAC9C,MAAM,WAAW,GAA2B,MAAM,OAAO,EAAE,CAAC;IAE5D,OAAO,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAC;AACpE,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"isSignedIn.js","sourceRoot":"","sources":["../../../src/server/actions/isSignedIn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAG1D,MAAM,UAAU,GAAG,KAAK,EAAE,SAAiB,EAAoB,EAAE;IAC/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;IAChD,MAAM,WAAW,GAAuB,MAAM,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAE/E,OAAO,CAAC,CAAC,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,35 @@
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 { EmbeddedSignInFlowHandleRequestPayload, EmbeddedFlowExecuteRequestConfig, EmbeddedSignInFlowInitiateResponse } from '@asgardeo/node';
19
+ /**
20
+ * Server action for signing in a user.
21
+ * Handles the embedded sign-in flow and manages session cookies.
22
+ *
23
+ * @param payload - The embedded sign-in flow payload
24
+ * @param request - The embedded flow execute request config
25
+ * @returns Promise that resolves when sign-in is complete
26
+ */
27
+ declare const signInAction: (payload?: EmbeddedSignInFlowHandleRequestPayload, request?: EmbeddedFlowExecuteRequestConfig) => Promise<{
28
+ success: boolean;
29
+ data?: {
30
+ afterSignInUrl?: string;
31
+ signInUrl?: string;
32
+ } | EmbeddedSignInFlowInitiateResponse;
33
+ error?: string;
34
+ }>;
35
+ export default signInAction;
@@ -0,0 +1,71 @@
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 server';
19
+ import { cookies } from 'next/headers';
20
+ import { CookieConfig, generateSessionId, EmbeddedSignInFlowStatus, } from '@asgardeo/node';
21
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
22
+ /**
23
+ * Server action for signing in a user.
24
+ * Handles the embedded sign-in flow and manages session cookies.
25
+ *
26
+ * @param payload - The embedded sign-in flow payload
27
+ * @param request - The embedded flow execute request config
28
+ * @returns Promise that resolves when sign-in is complete
29
+ */
30
+ const signInAction = async (payload, request) => {
31
+ try {
32
+ const client = AsgardeoNextClient.getInstance();
33
+ const cookieStore = await cookies();
34
+ let userId = cookieStore.get(CookieConfig.SESSION_COOKIE_NAME)?.value;
35
+ if (!userId) {
36
+ userId = generateSessionId();
37
+ cookieStore.set(CookieConfig.SESSION_COOKIE_NAME, userId, {
38
+ httpOnly: CookieConfig.DEFAULT_HTTP_ONLY,
39
+ maxAge: CookieConfig.DEFAULT_MAX_AGE,
40
+ sameSite: CookieConfig.DEFAULT_SAME_SITE,
41
+ secure: CookieConfig.DEFAULT_SECURE,
42
+ });
43
+ }
44
+ // If no payload provided, redirect to sign-in URL for redirect-based sign-in.
45
+ // If there's a payload, handle the embedded sign-in flow.
46
+ if (!payload) {
47
+ const defaultSignInUrl = await client.getAuthorizeRequestUrl({}, userId);
48
+ return { success: true, data: { signInUrl: String(defaultSignInUrl) } };
49
+ }
50
+ else {
51
+ const response = await client.signIn(payload, request, userId);
52
+ if (response.flowStatus === EmbeddedSignInFlowStatus.SuccessCompleted) {
53
+ // Complete the sign-in process
54
+ await client.signIn({
55
+ code: response?.authData?.code,
56
+ session_state: response?.authData?.session_state,
57
+ state: response?.authData?.state,
58
+ }, {}, userId);
59
+ const afterSignInUrl = await (await client.getStorageManager()).getConfigDataParameter('afterSignInUrl');
60
+ return { success: true, data: { afterSignInUrl: String(afterSignInUrl) } };
61
+ }
62
+ return { success: true, data: response };
63
+ }
64
+ }
65
+ catch (error) {
66
+ console.error('[signInAction] Error during sign-in:', error);
67
+ return { success: false, error: String(error) };
68
+ }
69
+ };
70
+ export default signInAction;
71
+ //# sourceMappingURL=signInAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signInAction.js","sourceRoot":"","sources":["../../../src/server/actions/signInAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GAIzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,KAAK,EACxB,OAAgD,EAChD,OAA0C,EAUzC,EAAE;IACH,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAChD,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;QAEpC,IAAI,MAAM,GAAuB,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAC;QAE1F,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,iBAAiB,EAAE,CAAC;YAC7B,WAAW,CAAC,GAAG,CAAC,YAAY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E,QAA8C,EAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC7D,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,25 @@
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
+ declare const signOutAction: () => Promise<{
19
+ success: boolean;
20
+ data?: {
21
+ afterSignOutUrl?: string;
22
+ };
23
+ error?: unknown;
24
+ }>;
25
+ export default signOutAction;
@@ -0,0 +1,33 @@
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 server';
19
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
20
+ import deleteSessionId from './deleteSessionId';
21
+ const signOutAction = async () => {
22
+ try {
23
+ const client = AsgardeoNextClient.getInstance();
24
+ const afterSignOutUrl = await client.signOut();
25
+ await deleteSessionId();
26
+ return { success: true, data: { afterSignOutUrl } };
27
+ }
28
+ catch (error) {
29
+ return { success: false, error };
30
+ }
31
+ };
32
+ export default signOutAction;
33
+ //# sourceMappingURL=signOutAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signOutAction.js","sourceRoot":"","sources":["../../../src/server/actions/signOutAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAGb,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,MAAM,aAAa,GAAG,KAAK,IAAqF,EAAE;IAChH,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAChD,MAAM,eAAe,GAAW,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QAEvD,MAAM,eAAe,EAAE,CAAC;QAExB,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAC,eAAe,EAAC,EAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,35 @@
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 { EmbeddedFlowExecuteRequestConfig, EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse } from '@asgardeo/node';
19
+ /**
20
+ * Server action for signing in a user.
21
+ * Handles the embedded sign-in flow and manages session cookies.
22
+ *
23
+ * @param payload - The embedded sign-in flow payload
24
+ * @param request - The embedded flow execute request config
25
+ * @returns Promise that resolves when sign-in is complete
26
+ */
27
+ declare const signUpAction: (payload?: EmbeddedFlowExecuteRequestPayload, request?: EmbeddedFlowExecuteRequestConfig) => Promise<{
28
+ success: boolean;
29
+ data?: {
30
+ afterSignUpUrl?: string;
31
+ signUpUrl?: string;
32
+ } | EmbeddedFlowExecuteResponse;
33
+ error?: string;
34
+ }>;
35
+ export default signUpAction;
@@ -0,0 +1,52 @@
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 server';
19
+ import { EmbeddedFlowStatus, } from '@asgardeo/node';
20
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
21
+ /**
22
+ * Server action for signing in a user.
23
+ * Handles the embedded sign-in flow and manages session cookies.
24
+ *
25
+ * @param payload - The embedded sign-in flow payload
26
+ * @param request - The embedded flow execute request config
27
+ * @returns Promise that resolves when sign-in is complete
28
+ */
29
+ const signUpAction = async (payload, request) => {
30
+ try {
31
+ const client = AsgardeoNextClient.getInstance();
32
+ // If no payload provided, redirect to sign-in URL for redirect-based sign-in.
33
+ // If there's a payload, handle the embedded sign-in flow.
34
+ if (!payload) {
35
+ const defaultSignUpUrl = '';
36
+ return { success: true, data: { signUpUrl: String(defaultSignUpUrl) } };
37
+ }
38
+ else {
39
+ const response = await client.signUp(payload);
40
+ if (response.flowStatus === EmbeddedFlowStatus.Complete) {
41
+ const afterSignUpUrl = await (await client.getStorageManager()).getConfigDataParameter('afterSignInUrl');
42
+ return { success: true, data: { afterSignUpUrl: String(afterSignUpUrl) } };
43
+ }
44
+ return { success: true, data: response };
45
+ }
46
+ }
47
+ catch (error) {
48
+ return { success: false, error: String(error) };
49
+ }
50
+ };
51
+ export default signUpAction;
52
+ //# sourceMappingURL=signUpAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signUpAction.js","sourceRoot":"","sources":["../../../src/server/actions/signUpAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,EAIL,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,KAAK,EACxB,OAA2C,EAC3C,OAA0C,EAUzC,EAAE;IACH,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAEhD,8EAA8E;QAC9E,0DAA0D;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,gBAAgB,GAAG,EAAE,CAAC;YAE5B,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAC,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAAC,EAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACN,MAAM,QAAQ,GAAQ,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAEnD,IAAI,QAAQ,CAAC,UAAU,KAAK,kBAAkB,CAAC,QAAQ,EAAE,CAAC;gBACxD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;gBAEzG,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAC,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,EAAC,EAAC,CAAC;YACzE,CAAC;YAED,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAuC,EAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,36 @@
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 { User } from '@asgardeo/node';
19
+ /**
20
+ * Server action to get the current user.
21
+ * Returns the user profile if signed in.
22
+ */
23
+ declare const updateUserProfileAction: (payload: any, sessionId: string) => Promise<{
24
+ success: boolean;
25
+ data: {
26
+ user: User;
27
+ };
28
+ error: null;
29
+ } | {
30
+ success: boolean;
31
+ data: {
32
+ user: {};
33
+ };
34
+ error: string;
35
+ }>;
36
+ export default updateUserProfileAction;
@@ -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
+ 'use server';
19
+ import AsgardeoNextClient from '../../AsgardeoNextClient';
20
+ /**
21
+ * Server action to get the current user.
22
+ * Returns the user profile if signed in.
23
+ */
24
+ const updateUserProfileAction = async (payload, sessionId) => {
25
+ try {
26
+ const client = AsgardeoNextClient.getInstance();
27
+ const user = await client.updateUserProfile(payload, sessionId);
28
+ return { success: true, data: { user }, error: null };
29
+ }
30
+ catch (error) {
31
+ return {
32
+ success: false,
33
+ data: {
34
+ user: {},
35
+ },
36
+ error: 'Failed to get user profile',
37
+ };
38
+ }
39
+ };
40
+ export default updateUserProfileAction;
41
+ //# sourceMappingURL=updateUserProfileAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateUserProfileAction.js","sourceRoot":"","sources":["../../../src/server/actions/updateUserProfileAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAGb,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,MAAM,uBAAuB,GAAG,KAAK,EAAE,OAAY,EAAE,SAAiB,EAAE,EAAE;IACxE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAChD,MAAM,IAAI,GAAS,MAAM,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtE,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE,EAAE;aACT;YACD,KAAK,EAAE,4BAA4B;SACpC,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
@@ -16,12 +16,16 @@
16
16
  * under the License.
17
17
  */
18
18
  const decorateConfigWithNextEnv = (config) => {
19
- const { baseUrl, clientId, clientSecret, ...rest } = config;
19
+ const { baseUrl, clientId, clientSecret, signInUrl, signUpUrl, afterSignInUrl, afterSignOutUrl, ...rest } = config;
20
20
  return {
21
21
  ...rest,
22
22
  baseUrl: baseUrl || process.env['NEXT_PUBLIC_ASGARDEO_BASE_URL'],
23
23
  clientId: clientId || process.env['NEXT_PUBLIC_ASGARDEO_CLIENT_ID'],
24
24
  clientSecret: clientSecret || process.env['ASGARDEO_CLIENT_SECRET'],
25
+ afterSignInUrl: afterSignInUrl || process.env['NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_IN_URL'],
26
+ signInUrl: signInUrl || process.env['NEXT_PUBLIC_ASGARDEO_SIGN_IN_URL'],
27
+ afterSignOutUrl: afterSignOutUrl || process.env['NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_OUT_URL'],
28
+ signUpUrl: signUpUrl || process.env['NEXT_PUBLIC_ASGARDEO_SIGN_UP_URL'],
25
29
  };
26
30
  };
27
31
  export default decorateConfigWithNextEnv;
@@ -1 +1 @@
1
- {"version":3,"file":"decorateConfigWithNextEnv.js","sourceRoot":"","sources":["../../src/utils/decorateConfigWithNextEnv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAI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K,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAY;KACpF,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgardeo/nextjs",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Next.js implementation of Asgardeo JavaScript SDK.",
5
5
  "keywords": [
6
6
  "asgardeo",
@@ -19,8 +19,18 @@
19
19
  "module": "dist/index.js",
20
20
  "commonjs": "dist/cjs/index.js",
21
21
  "exports": {
22
- "import": "./dist/index.js",
23
- "require": "./dist/cjs/index.js"
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/cjs/index.js"
25
+ },
26
+ "./middleware": {
27
+ "import": "./dist/middleware/index.js",
28
+ "require": "./dist/cjs/middleware/index.js"
29
+ },
30
+ "./server": {
31
+ "import": "./dist/server/index.js",
32
+ "require": "./dist/cjs/server/index.js"
33
+ }
24
34
  },
25
35
  "files": [
26
36
  "dist",
@@ -37,7 +47,7 @@
37
47
  "@types/react": "^19.1.4",
38
48
  "tslib": "^2.8.1",
39
49
  "@asgardeo/node": "^0.0.2",
40
- "@asgardeo/react": "^0.4.0"
50
+ "@asgardeo/react": "^0.5.1"
41
51
  },
42
52
  "devDependencies": {
43
53
  "@types/node": "^22.15.3",