@asgardeo/nextjs 0.0.1 → 0.0.3

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 (56) hide show
  1. package/dist/AsgardeoNextClient.d.ts +10 -3
  2. package/dist/AsgardeoNextClient.js +124 -36
  3. package/dist/AsgardeoNextClient.js.map +1 -1
  4. package/dist/cjs/index.js +17 -12
  5. package/dist/cjs/index.js.map +3 -3
  6. package/dist/client/components/actions/SignInButton/SignInButton.d.ts +49 -0
  7. package/dist/client/components/actions/SignInButton/SignInButton.js +52 -0
  8. package/dist/client/components/actions/SignInButton/SignInButton.js.map +1 -0
  9. package/dist/client/components/actions/{SignOutButton.d.ts → SignOutButton/SignOutButton.d.ts} +3 -2
  10. package/dist/client/components/actions/{SignOutButton.js → SignOutButton/SignOutButton.js} +2 -2
  11. package/dist/client/components/actions/SignOutButton/SignOutButton.js.map +1 -0
  12. package/dist/client/components/actions/{SignUpButton.d.ts → SignUpButton/SignUpButton.d.ts} +3 -2
  13. package/dist/client/components/actions/{SignUpButton.js → SignUpButton/SignUpButton.js} +2 -2
  14. package/dist/client/components/actions/SignUpButton/SignUpButton.js.map +1 -0
  15. package/dist/client/components/control/{SignedIn.js → SignedIn/SignedIn.js} +1 -1
  16. package/dist/client/components/control/SignedIn/SignedIn.js.map +1 -0
  17. package/dist/client/components/control/{SignedOut.js → SignedOut/SignedOut.js} +1 -1
  18. package/dist/client/components/control/SignedOut/SignedOut.js.map +1 -0
  19. package/dist/client/components/presentation/SignIn/SignIn.d.ts +69 -0
  20. package/dist/client/components/presentation/SignIn/SignIn.js +82 -0
  21. package/dist/client/components/presentation/SignIn/SignIn.js.map +1 -0
  22. package/dist/client/components/presentation/User/User.d.ts +61 -0
  23. package/dist/client/components/presentation/User/User.js +52 -0
  24. package/dist/client/components/presentation/User/User.js.map +1 -0
  25. package/dist/client/contexts/{AsgardeoContext.d.ts → Asgardeo/AsgardeoContext.d.ts} +8 -1
  26. package/dist/client/contexts/Asgardeo/AsgardeoContext.js.map +1 -0
  27. package/dist/client/{providers → contexts/Asgardeo}/AsgardeoProvider.d.ts +6 -1
  28. package/dist/client/contexts/Asgardeo/AsgardeoProvider.js +95 -0
  29. package/dist/client/contexts/Asgardeo/AsgardeoProvider.js.map +1 -0
  30. package/dist/client/{hooks → contexts/Asgardeo}/useAsgardeo.d.ts +1 -1
  31. package/dist/client/{hooks → contexts/Asgardeo}/useAsgardeo.js +1 -1
  32. package/dist/client/contexts/Asgardeo/useAsgardeo.js.map +1 -0
  33. package/dist/configs/InternalAuthAPIRoutesConfig.js +1 -0
  34. package/dist/configs/InternalAuthAPIRoutesConfig.js.map +1 -1
  35. package/dist/index.d.ts +12 -10
  36. package/dist/index.js +6 -7
  37. package/dist/index.js.map +1 -1
  38. package/dist/models/api.d.ts +5 -0
  39. package/dist/server/AsgardeoProvider.d.ts +1 -1
  40. package/dist/server/AsgardeoProvider.js +1 -1
  41. package/dist/server/AsgardeoProvider.js.map +1 -1
  42. package/package.json +6 -6
  43. package/dist/client/components/actions/SignInButton.d.ts +0 -41
  44. package/dist/client/components/actions/SignInButton.js +0 -42
  45. package/dist/client/components/actions/SignInButton.js.map +0 -1
  46. package/dist/client/components/actions/SignOutButton.js.map +0 -1
  47. package/dist/client/components/actions/SignUpButton.js.map +0 -1
  48. package/dist/client/components/control/SignedIn.js.map +0 -1
  49. package/dist/client/components/control/SignedOut.js.map +0 -1
  50. package/dist/client/contexts/AsgardeoContext.js.map +0 -1
  51. package/dist/client/hooks/useAsgardeo.js.map +0 -1
  52. package/dist/client/providers/AsgardeoProvider.js +0 -23
  53. package/dist/client/providers/AsgardeoProvider.js.map +0 -1
  54. /package/dist/client/components/control/{SignedIn.d.ts → SignedIn/SignedIn.d.ts} +0 -0
  55. /package/dist/client/components/control/{SignedOut.d.ts → SignedOut/SignedOut.d.ts} +0 -0
  56. /package/dist/client/contexts/{AsgardeoContext.js → Asgardeo/AsgardeoContext.js} +0 -0
@@ -0,0 +1,69 @@
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 { BaseSignInProps } from '@asgardeo/react';
19
+ import { FC } from 'react';
20
+ /**
21
+ * Props for the SignIn component.
22
+ * Extends BaseSignInProps for full compatibility with the React BaseSignIn component
23
+ */
24
+ export type SignInProps = BaseSignInProps;
25
+ /**
26
+ * A SignIn component for Next.js that provides native authentication flow.
27
+ * This component delegates to the BaseSignIn from @asgardeo/react and requires
28
+ * the API functions to be provided as props.
29
+ *
30
+ * @remarks This component requires the authentication API functions to be provided
31
+ * as props. For a complete working example, you'll need to implement the server-side
32
+ * authentication endpoints or use the traditional OAuth flow with SignInButton.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * import { SignIn } from '@asgardeo/nextjs';
37
+ * import { executeEmbeddedSignInFlow } from '@asgardeo/browser';
38
+ *
39
+ * const LoginPage = () => {
40
+ * const handleInitialize = async () => {
41
+ * return await executeEmbeddedSignInFlow({
42
+ * response_mode: 'direct',
43
+ * });
44
+ * };
45
+ *
46
+ * const handleSubmit = async (flow) => {
47
+ * return await executeEmbeddedSignInFlow({ flow });
48
+ * };
49
+ *
50
+ * return (
51
+ * <SignIn
52
+ * onInitialize={handleInitialize}
53
+ * onSubmit={handleSubmit}
54
+ * onSuccess={(authData) => {
55
+ * console.log('Authentication successful:', authData);
56
+ * }}
57
+ * onError={(error) => {
58
+ * console.error('Authentication failed:', error);
59
+ * }}
60
+ * size="medium"
61
+ * variant="outlined"
62
+ * afterSignInUrl="/dashboard"
63
+ * />
64
+ * );
65
+ * };
66
+ * ```
67
+ */
68
+ declare const SignIn: FC<SignInProps>;
69
+ export default SignIn;
@@ -0,0 +1,82 @@
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 { BaseSignIn } from '@asgardeo/react';
21
+ import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
22
+ /**
23
+ * A SignIn component for Next.js that provides native authentication flow.
24
+ * This component delegates to the BaseSignIn from @asgardeo/react and requires
25
+ * the API functions to be provided as props.
26
+ *
27
+ * @remarks This component requires the authentication API functions to be provided
28
+ * as props. For a complete working example, you'll need to implement the server-side
29
+ * authentication endpoints or use the traditional OAuth flow with SignInButton.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { SignIn } from '@asgardeo/nextjs';
34
+ * import { executeEmbeddedSignInFlow } from '@asgardeo/browser';
35
+ *
36
+ * const LoginPage = () => {
37
+ * const handleInitialize = async () => {
38
+ * return await executeEmbeddedSignInFlow({
39
+ * response_mode: 'direct',
40
+ * });
41
+ * };
42
+ *
43
+ * const handleSubmit = async (flow) => {
44
+ * return await executeEmbeddedSignInFlow({ flow });
45
+ * };
46
+ *
47
+ * return (
48
+ * <SignIn
49
+ * onInitialize={handleInitialize}
50
+ * onSubmit={handleSubmit}
51
+ * onSuccess={(authData) => {
52
+ * console.log('Authentication successful:', authData);
53
+ * }}
54
+ * onError={(error) => {
55
+ * console.error('Authentication failed:', error);
56
+ * }}
57
+ * size="medium"
58
+ * variant="outlined"
59
+ * afterSignInUrl="/dashboard"
60
+ * />
61
+ * );
62
+ * };
63
+ * ```
64
+ */
65
+ const SignIn = ({ afterSignInUrl, className, onError, onFlowChange, onInitialize, onSubmit, onSuccess, size = 'medium', variant = 'outlined', ...rest }) => {
66
+ const { signIn } = useAsgardeo();
67
+ const handleInitialize = async () => await signIn({
68
+ flowId: '',
69
+ selectedAuthenticator: {
70
+ authenticatorId: '',
71
+ params: {},
72
+ },
73
+ });
74
+ const handleOnSubmit = async (payload, request) => await signIn(payload, request);
75
+ const handleError = (error) => {
76
+ onError?.(error);
77
+ };
78
+ return (_jsx(BaseSignIn, { afterSignInUrl: afterSignInUrl, onInitialize: handleInitialize, onSubmit: handleOnSubmit, onSuccess: onSuccess, onError: handleError, onFlowChange: onFlowChange, className: className, size: size, variant: variant, ...rest }));
79
+ };
80
+ SignIn.displayName = 'SignIn';
81
+ export default SignIn;
82
+ //# sourceMappingURL=SignIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignIn.js","sourceRoot":"","sources":["../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;AAQb,OAAO,EAAC,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AAE5D,OAAO,WAAW,MAAM,wCAAwC,CAAC;AAQjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,MAAM,GAAoB,CAAC,EAC/B,cAAc,EACd,SAAS,EACT,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,IAAI,GAAG,QAAQ,EACf,OAAO,GAAG,UAAU,EACpB,GAAG,IAAI,EACK,EAAE,EAAE;IAChB,MAAM,EAAC,MAAM,EAAC,GAAG,WAAW,EAAE,CAAC;IAE/B,MAAM,gBAAgB,GAAG,KAAK,IAAiD,EAAE,CAC/E,MAAM,MAAM,CAAC;QACX,MAAM,EAAE,EAAE;QACV,qBAAqB,EAAE;YACrB,eAAe,EAAE,EAAE;YACnB,MAAM,EAAE,EAAE;SACX;KACF,CAAC,CAAC;IAEL,MAAM,cAAc,GAAG,KAAK,EAC1B,OAA+C,EAC/C,OAAyC,EACE,EAAE,CAAC,MAAM,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE/E,MAAM,WAAW,GAAG,CAAC,KAAY,EAAQ,EAAE;QACzC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,UAAU,IACT,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,KACZ,IAAI,GACR,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC;AAE9B,eAAe,MAAM,CAAC"}
@@ -0,0 +1,61 @@
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, ReactNode } from 'react';
19
+ import { BaseUserProps } from '@asgardeo/react';
20
+ /**
21
+ * Props for the User component.
22
+ * Extends BaseUserProps but makes the user prop optional since it will be obtained from useAsgardeo
23
+ */
24
+ export interface UserProps extends Omit<BaseUserProps, 'user'> {
25
+ /**
26
+ * Render prop that takes the user object and returns a ReactNode.
27
+ * @param user - The authenticated user object from Asgardeo.
28
+ * @returns A ReactNode to render.
29
+ */
30
+ children: (user: any | null) => ReactNode;
31
+ /**
32
+ * Optional element to render when no user is signed in.
33
+ */
34
+ fallback?: ReactNode;
35
+ }
36
+ /**
37
+ * A component that uses render props to expose the authenticated user object.
38
+ * This component automatically retrieves the user from Asgardeo context.
39
+ *
40
+ * @remarks This component is only supported in browser based React applications (CSR).
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * import { User } from '@asgardeo/auth-react';
45
+ *
46
+ * const App = () => {
47
+ * return (
48
+ * <User fallback={<p>Please sign in</p>}>
49
+ * {(user) => (
50
+ * <div>
51
+ * <h1>Welcome, {user.displayName}!</h1>
52
+ * <p>Email: {user.email}</p>
53
+ * </div>
54
+ * )}
55
+ * </User>
56
+ * );
57
+ * }
58
+ * ```
59
+ */
60
+ declare const User: FC<UserProps>;
61
+ export default User;
@@ -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 client';
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
21
+ import { BaseUser } from '@asgardeo/react';
22
+ /**
23
+ * A component that uses render props to expose the authenticated user object.
24
+ * This component automatically retrieves the user from Asgardeo context.
25
+ *
26
+ * @remarks This component is only supported in browser based React applications (CSR).
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * import { User } from '@asgardeo/auth-react';
31
+ *
32
+ * const App = () => {
33
+ * return (
34
+ * <User fallback={<p>Please sign in</p>}>
35
+ * {(user) => (
36
+ * <div>
37
+ * <h1>Welcome, {user.displayName}!</h1>
38
+ * <p>Email: {user.email}</p>
39
+ * </div>
40
+ * )}
41
+ * </User>
42
+ * );
43
+ * }
44
+ * ```
45
+ */
46
+ const User = ({ children, fallback = null }) => {
47
+ const { user } = useAsgardeo();
48
+ return (_jsx(BaseUser, { user: user, fallback: fallback, children: children }));
49
+ };
50
+ User.displayName = 'User';
51
+ export default User;
52
+ //# sourceMappingURL=User.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../../../src/client/components/presentation/User/User.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;AAGb,OAAO,WAAW,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAC,QAAQ,EAAgB,MAAM,iBAAiB,CAAC;AAoBxD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,IAAI,GAAkB,CAAC,EAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAC,EAAgB,EAAE;IACxE,MAAM,EAAC,IAAI,EAAC,GAAG,WAAW,EAAE,CAAC;IAE7B,OAAO,CACL,KAAC,QAAQ,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,YACrC,QAAQ,GACA,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;AAE1B,eAAe,IAAI,CAAC"}
@@ -16,11 +16,18 @@
16
16
  * under the License.
17
17
  */
18
18
  import { AsgardeoContextProps as AsgardeoReactContextProps } from '@asgardeo/react';
19
+ import { EmbeddedFlowExecuteRequestConfig, EmbeddedSignInFlowHandleRequestPayload, User } from '@asgardeo/node';
19
20
  import { Context } from 'react';
20
21
  /**
21
22
  * Props interface of {@link AsgardeoContext}
22
23
  */
23
- export type AsgardeoContextProps = Partial<AsgardeoReactContextProps>;
24
+ export type AsgardeoContextProps = Partial<AsgardeoReactContextProps> & {
25
+ user?: User | null;
26
+ isSignedIn?: boolean;
27
+ isLoading?: boolean;
28
+ signIn?: (payload: EmbeddedSignInFlowHandleRequestPayload, request: EmbeddedFlowExecuteRequestConfig) => void;
29
+ signOut?: () => void;
30
+ };
24
31
  /**
25
32
  * Context object for managing the Authentication flow builder core context.
26
33
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsgardeoContext.js","sourceRoot":"","sources":["../../../../src/client/contexts/Asgardeo/AsgardeoContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAIb,OAAO,EAAU,aAAa,EAAC,MAAM,OAAO,CAAC;AAa7C;;GAEG;AACH,MAAM,eAAe,GAAyC,aAAa,CAA8B,EAAE,CAAC,CAAC;AAE7G,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,eAAe,eAAe,CAAC"}
@@ -19,6 +19,11 @@ import { FC, PropsWithChildren } from 'react';
19
19
  /**
20
20
  * Props interface of {@link AsgardeoClientProvider}
21
21
  */
22
- export type AsgardeoClientProviderProps = {};
22
+ export type AsgardeoClientProviderProps = {
23
+ /**
24
+ * Preferences for theming, i18n, and other UI customizations.
25
+ */
26
+ preferences?: any;
27
+ };
23
28
  declare const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>;
24
29
  export default AsgardeoClientProvider;
@@ -0,0 +1,95 @@
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 { I18nProvider, FlowProvider, UserProvider, ThemeProvider } from '@asgardeo/react';
21
+ import { useEffect, useMemo, useState } from 'react';
22
+ import { useRouter } from 'next/navigation';
23
+ import AsgardeoContext from './AsgardeoContext';
24
+ import InternalAuthAPIRoutesConfig from '../../../configs/InternalAuthAPIRoutesConfig';
25
+ const AsgardeoClientProvider = ({ children, preferences, }) => {
26
+ const router = useRouter();
27
+ const [isDarkMode, setIsDarkMode] = useState(false);
28
+ const [user, setUser] = useState(null);
29
+ const [isLoading, setIsLoading] = useState(true);
30
+ const [isSignedIn, setIsSignedIn] = useState(false);
31
+ useEffect(() => {
32
+ if (!preferences?.theme?.mode || preferences.theme.mode === 'system') {
33
+ setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches);
34
+ }
35
+ else {
36
+ setIsDarkMode(preferences.theme.mode === 'dark');
37
+ }
38
+ }, [preferences?.theme?.mode]);
39
+ useEffect(() => {
40
+ const fetchUserData = async () => {
41
+ try {
42
+ setIsLoading(true);
43
+ const sessionResponse = await fetch(InternalAuthAPIRoutesConfig.session);
44
+ const sessionData = await sessionResponse.json();
45
+ setIsSignedIn(sessionData.isSignedIn);
46
+ if (sessionData.isSignedIn) {
47
+ const userResponse = await fetch(InternalAuthAPIRoutesConfig.user);
48
+ if (userResponse.ok) {
49
+ const userData = await userResponse.json();
50
+ setUser(userData);
51
+ }
52
+ }
53
+ else {
54
+ setUser(null);
55
+ }
56
+ }
57
+ catch (error) {
58
+ setUser(null);
59
+ setIsSignedIn(false);
60
+ }
61
+ finally {
62
+ setIsLoading(false);
63
+ }
64
+ };
65
+ fetchUserData();
66
+ }, []);
67
+ const signIn = async (payload, request) => {
68
+ const response = await fetch(InternalAuthAPIRoutesConfig.signIn, {
69
+ method: 'POST',
70
+ body: JSON.stringify({
71
+ payload,
72
+ request,
73
+ }),
74
+ });
75
+ if (response.redirected && response.url) {
76
+ router.push(response.url);
77
+ return { redirected: true, location: response.url };
78
+ }
79
+ return response.json();
80
+ };
81
+ const contextValue = useMemo(() => ({
82
+ user,
83
+ isSignedIn,
84
+ isLoading,
85
+ signIn,
86
+ signOut: () => (window.location.href = InternalAuthAPIRoutesConfig.signOut),
87
+ }), [user, isSignedIn, isLoading]);
88
+ return (_jsx(AsgardeoContext.Provider, { value: contextValue, children: _jsx(I18nProvider, { preferences: preferences?.i18n, children: _jsx(ThemeProvider, { theme: preferences?.theme?.overrides, defaultColorScheme: isDarkMode ? 'dark' : 'light', children: _jsx(FlowProvider, { children: _jsx(UserProvider, { profile: {
89
+ schemas: [],
90
+ profile: user || {},
91
+ flattenedProfile: user || {},
92
+ }, children: children }) }) }) }) }));
93
+ };
94
+ export default AsgardeoClientProvider;
95
+ //# sourceMappingURL=AsgardeoProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../../../src/client/contexts/Asgardeo/AsgardeoProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;AAGb,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAwB,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C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I;QACJ,UAAU;QACV,SAAS;QACT,MAAM;QACN,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,2BAA2B,CAAC,OAAO,CAAC;KAC5E,CAAC,EACF,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,CAC9B,CAAC;IAEF,OAAO,CACL,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,KAAC,YAAY,IAAC,WAAW,EAAE,WAAW,EAAE,IAAI,YAC1C,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,YACpG,KAAC,YAAY,cACX,KAAC,YAAY,IACX,OAAO,EAAE;4BACP,OAAO,EAAE,EAAE;4BACX,OAAO,EAAE,IAAI,IAAI,EAAE;4BACnB,gBAAgB,EAAE,IAAI,IAAI,EAAE;yBAC7B,YAEA,QAAQ,GACI,GACF,GACD,GACH,GACU,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -15,6 +15,6 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AsgardeoContextProps } from '../contexts/AsgardeoContext';
18
+ import { AsgardeoContextProps } from './AsgardeoContext';
19
19
  declare const useAsgardeo: () => AsgardeoContextProps;
20
20
  export default useAsgardeo;
@@ -17,7 +17,7 @@
17
17
  */
18
18
  'use client';
19
19
  import { useContext } from 'react';
20
- import AsgardeoContext from '../contexts/AsgardeoContext';
20
+ import AsgardeoContext from './AsgardeoContext';
21
21
  const useAsgardeo = () => {
22
22
  const context = useContext(AsgardeoContext);
23
23
  if (!context) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsgardeo.js","sourceRoot":"","sources":["../../../../src/client/contexts/Asgardeo/useAsgardeo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;AAEb,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,eAAuC,MAAM,mBAAmB,CAAC;AAExE,MAAM,WAAW,GAAG,GAAyB,EAAE;IAC7C,MAAM,OAAO,GAAgC,UAAU,CAAC,eAAe,CAAC,CAAC;IAEzE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -16,6 +16,7 @@
16
16
  * under the License.
17
17
  */
18
18
  const InternalAuthAPIRoutesConfig = {
19
+ user: '/api/auth/user',
19
20
  session: '/api/auth/session',
20
21
  signIn: '/api/auth/signin',
21
22
  signOut: '/api/auth/signout',
@@ -1 +1 @@
1
- {"version":3,"file":"InternalAuthAPIRoutesConfig.js","sourceRoot":"","sources":["../../src/configs/InternalAuthAPIRoutesConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,2BAA2B,GAA0B;IACzD,OAAO,EAAE,mBAAmB;IAC5B,MAAM,EAAE,kBAAkB;IAC1B,OAAO,EAAE,mBAAmB;IAC5B,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
1
+ {"version":3,"file":"InternalAuthAPIRoutesConfig.js","sourceRoot":"","sources":["../../src/configs/InternalAuthAPIRoutesConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,2BAA2B,GAA0B;IACzD,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,mBAAmB;IAC5B,MAAM,EAAE,kBAAkB;IAC1B,OAAO,EAAE,mBAAmB;IAC5B,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -18,14 +18,16 @@
18
18
  export { default as AsgardeoProvider } from './server/AsgardeoProvider';
19
19
  export * from './server/AsgardeoProvider';
20
20
  export { default as isSignedIn } from './server/actions/isSignedIn';
21
- export { default as SignedIn } from './client/components/control/SignedIn';
22
- export * from './client/components/control/SignedIn';
23
- export { default as SignedOut } from './client/components/control/SignedOut';
24
- export * from './client/components/control/SignedOut';
25
- export { default as SignInButton } from './client/components/actions/SignInButton';
26
- export type { SignInButtonProps } from './client/components/actions/SignInButton';
27
- export { default as SignOutButton } from './client/components/actions/SignOutButton';
28
- export type { SignOutButtonProps } from './client/components/actions/SignOutButton';
29
- export { default as AsgardeoContext } from './client/contexts/AsgardeoContext';
30
- export type { AsgardeoContextProps } from './client/contexts/AsgardeoContext';
21
+ export { default as SignedIn } from './client/components/control/SignedIn/SignedIn';
22
+ export { SignedInProps } from './client/components/control/SignedIn/SignedIn';
23
+ export { default as SignedOut } from './client/components/control/SignedOut/SignedOut';
24
+ export { SignedOutProps } from './client/components/control/SignedOut/SignedOut';
25
+ export { default as SignInButton } from './client/components/actions/SignInButton/SignInButton';
26
+ export type { SignInButtonProps } from './client/components/actions/SignInButton/SignInButton';
27
+ export { default as SignIn } from './client/components/presentation/SignIn/SignIn';
28
+ export type { SignInProps } from './client/components/presentation/SignIn/SignIn';
29
+ export { default as SignOutButton } from './client/components/actions/SignOutButton/SignOutButton';
30
+ export type { SignOutButtonProps } from './client/components/actions/SignOutButton/SignOutButton';
31
+ export { default as User } from './client/components/presentation/User/User';
32
+ export type { UserProps } from './client/components/presentation/User/User';
31
33
  export { default as AsgardeoNext } from './AsgardeoNextClient';
package/dist/index.js CHANGED
@@ -18,12 +18,11 @@
18
18
  export { default as AsgardeoProvider } from './server/AsgardeoProvider';
19
19
  export * from './server/AsgardeoProvider';
20
20
  export { default as isSignedIn } from './server/actions/isSignedIn';
21
- export { default as SignedIn } from './client/components/control/SignedIn';
22
- export * from './client/components/control/SignedIn';
23
- export { default as SignedOut } from './client/components/control/SignedOut';
24
- export * from './client/components/control/SignedOut';
25
- export { default as SignInButton } from './client/components/actions/SignInButton';
26
- export { default as SignOutButton } from './client/components/actions/SignOutButton';
27
- export { default as AsgardeoContext } from './client/contexts/AsgardeoContext';
21
+ export { default as SignedIn } from './client/components/control/SignedIn/SignedIn';
22
+ export { default as SignedOut } from './client/components/control/SignedOut/SignedOut';
23
+ export { default as SignInButton } from './client/components/actions/SignInButton/SignInButton';
24
+ export { default as SignIn } from './client/components/presentation/SignIn/SignIn';
25
+ export { default as SignOutButton } from './client/components/actions/SignOutButton/SignOutButton';
26
+ export { default as User } from './client/components/presentation/User/User';
28
27
  export { default as AsgardeoNext } from './AsgardeoNextClient';
29
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AACtE,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,sCAAsC,CAAC;AACzE,cAAc,sCAAsC,CAAC;AAErD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,uCAAuC,CAAC;AAC3E,cAAc,uCAAuC,CAAC;AAEtD,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,0CAA0C,CAAC;AAGjF,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,2CAA2C,CAAC;AAGnF,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mCAAmC,CAAC;AAG7E,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AACtE,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,+CAA+C,CAAC;AAGlF,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,iDAAiD,CAAC;AAGrF,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,uDAAuD,CAAC;AAG9F,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,gDAAgD,CAAC;AAGjF,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,yDAAyD,CAAC;AAGjG,OAAO,EAAC,OAAO,IAAI,IAAI,EAAC,MAAM,4CAA4C,CAAC;AAG3E,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,sBAAsB,CAAC"}
@@ -20,6 +20,11 @@
20
20
  * These routes are used internally by the Asgardeo Next.js SDK for handling authentication flows.
21
21
  */
22
22
  export interface InternalAuthAPIRoutes {
23
+ /**
24
+ * Route for handling user information retrieval.
25
+ * This route should return the current user's information, such as username, email, etc.
26
+ */
27
+ user: string;
23
28
  /**
24
29
  * Route for handling session management.
25
30
  * This route should return the current signed-in status.
@@ -16,7 +16,7 @@
16
16
  * under the License.
17
17
  */
18
18
  import { FC, PropsWithChildren } from 'react';
19
- import { AsgardeoClientProviderProps } from '../client/providers/AsgardeoProvider';
19
+ import { AsgardeoClientProviderProps } from '../client/contexts/Asgardeo/AsgardeoProvider';
20
20
  /**
21
21
  * Props interface of {@link AsgardeoServerProvider}
22
22
  */
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import AsgardeoClientProvider from '../client/providers/AsgardeoProvider';
2
+ import AsgardeoClientProvider from '../client/contexts/Asgardeo/AsgardeoProvider';
3
3
  /**
4
4
  * Server-side provider component for Asgardeo authentication.
5
5
  * Wraps the client-side provider and handles server-side authentication logic.
@@ -1 +1 @@
1
- {"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../src/server/AsgardeoProvider.tsx"],"names":[],"mappings":";AAmBA,OAAO,sBAAqD,MAAM,sCAAsC,CAAC;AAOzG;;;;;;;;;;;;;;GAcG;AACH,MAAM,sBAAsB,GAAuD,CAAC,EAClF,QAAQ,GACuC,EAAgB,EAAE,CAAC,CAClE,KAAC,sBAAsB,cAAE,QAAQ,GAA0B,CAC5D,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../src/server/AsgardeoProvider.tsx"],"names":[],"mappings":";AAmBA,OAAO,sBAAqD,MAAM,8CAA8C,CAAC;AAOjH;;;;;;;;;;;;;;GAcG;AACH,MAAM,sBAAsB,GAAuD,CAAC,EAClF,QAAQ,GACuC,EAAgB,EAAE,CAAC,CAClE,KAAC,sBAAsB,cAAE,QAAQ,GAA0B,CAC5D,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgardeo/nextjs",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Next.js implementation of Asgardeo JavaScript SDK.",
5
5
  "keywords": [
6
6
  "asgardeo",
@@ -8,9 +8,9 @@
8
8
  "react",
9
9
  "ssr"
10
10
  ],
11
- "homepage": "https://github.com/asgardeo/javascript/tree/main/packages/next#readme",
11
+ "homepage": "https://github.com/asgardeo/web-ui-sdks/tree/main/packages/next#readme",
12
12
  "bugs": {
13
- "url": "https://github.com/asgardeo/javascript/issues"
13
+ "url": "https://github.com/asgardeo/web-ui-sdks/issues"
14
14
  },
15
15
  "author": "WSO2",
16
16
  "license": "Apache-2.0",
@@ -30,14 +30,14 @@
30
30
  "types": "dist/index.d.ts",
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/asgardeo/javascript",
33
+ "url": "https://github.com/asgardeo/web-ui-sdks",
34
34
  "directory": "packages/next"
35
35
  },
36
36
  "dependencies": {
37
37
  "@types/react": "^19.1.4",
38
38
  "tslib": "^2.8.1",
39
- "@asgardeo/node": "^0.0.1",
40
- "@asgardeo/react": "^0.3.0"
39
+ "@asgardeo/node": "^0.0.2",
40
+ "@asgardeo/react": "^0.5.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^22.15.3",
@@ -1,41 +0,0 @@
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;