@asgardeo/nextjs 0.0.3 → 0.1.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.
- package/README.md +68 -8
- package/dist/AsgardeoNextClient.d.ts +37 -8
- package/dist/AsgardeoNextClient.js +153 -138
- package/dist/AsgardeoNextClient.js.map +1 -1
- package/dist/cjs/index.js +25 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/client/components/actions/SignInButton/SignInButton.d.ts +2 -2
- package/dist/client/components/actions/SignInButton/SignInButton.js +34 -7
- package/dist/client/components/actions/SignInButton/SignInButton.js.map +1 -1
- package/dist/client/components/actions/SignOutButton/SignOutButton.d.ts +1 -2
- package/dist/client/components/actions/SignOutButton/SignOutButton.js +25 -4
- package/dist/client/components/actions/SignOutButton/SignOutButton.js.map +1 -1
- package/dist/client/components/actions/SignUpButton/SignUpButton.d.ts +38 -14
- package/dist/client/components/actions/SignUpButton/SignUpButton.js +69 -15
- package/dist/client/components/actions/SignUpButton/SignUpButton.js.map +1 -1
- package/dist/client/components/control/SignedIn/SignedIn.js +3 -17
- package/dist/client/components/control/SignedIn/SignedIn.js.map +1 -1
- package/dist/client/components/control/SignedOut/SignedOut.js +3 -17
- package/dist/client/components/control/SignedOut/SignedOut.js.map +1 -1
- package/dist/client/components/presentation/SignIn/SignIn.d.ts +1 -1
- package/dist/client/components/presentation/SignIn/SignIn.js +9 -6
- package/dist/client/components/presentation/SignIn/SignIn.js.map +1 -1
- package/dist/client/components/presentation/SignUp/SignUp.d.ts +55 -0
- package/dist/client/components/presentation/SignUp/SignUp.js +70 -0
- package/dist/client/components/presentation/SignUp/SignUp.js.map +1 -0
- package/dist/client/components/presentation/UserDropdown/UserDropdown.d.ts +105 -0
- package/dist/client/components/presentation/UserDropdown/UserDropdown.js +106 -0
- package/dist/client/components/presentation/UserDropdown/UserDropdown.js.map +1 -0
- package/dist/client/components/presentation/UserProfile/UserProfile.d.ts +49 -0
- package/dist/client/components/presentation/UserProfile/UserProfile.js +57 -0
- package/dist/client/components/presentation/UserProfile/UserProfile.js.map +1 -0
- package/dist/client/contexts/Asgardeo/AsgardeoContext.d.ts +1 -8
- package/dist/client/contexts/Asgardeo/AsgardeoContext.js +13 -1
- package/dist/client/contexts/Asgardeo/AsgardeoContext.js.map +1 -1
- package/dist/client/contexts/Asgardeo/AsgardeoProvider.d.ts +15 -5
- package/dist/client/contexts/Asgardeo/AsgardeoProvider.js +115 -49
- package/dist/client/contexts/Asgardeo/AsgardeoProvider.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/middleware/asgardeoMiddleware.d.ts +63 -0
- package/dist/middleware/asgardeoMiddleware.js +115 -0
- package/dist/middleware/asgardeoMiddleware.js.map +1 -0
- package/dist/server/AsgardeoProvider.d.ts +6 -3
- package/dist/server/AsgardeoProvider.js +42 -3
- package/dist/server/AsgardeoProvider.js.map +1 -1
- package/dist/server/actions/getClientOrigin.d.ts +2 -0
- package/dist/server/actions/getClientOrigin.js +10 -0
- package/dist/server/actions/getClientOrigin.js.map +1 -0
- package/dist/server/actions/getUserAction.d.ts +35 -0
- package/dist/server/actions/getUserAction.js +35 -0
- package/dist/server/actions/getUserAction.js.map +1 -0
- package/dist/server/actions/getUserProfileAction.d.ts +40 -0
- package/dist/server/actions/getUserProfileAction.js +45 -0
- package/dist/server/actions/getUserProfileAction.js.map +1 -0
- package/dist/server/actions/handleOAuthCallbackAction.d.ts +33 -0
- package/dist/server/actions/handleOAuthCallbackAction.js +80 -0
- package/dist/server/actions/handleOAuthCallbackAction.js.map +1 -0
- package/dist/server/actions/isSignedIn.d.ts +1 -1
- package/dist/server/actions/isSignedIn.js +5 -5
- package/dist/server/actions/isSignedIn.js.map +1 -1
- package/dist/server/actions/signInAction.d.ts +35 -0
- package/dist/server/actions/signInAction.js +71 -0
- package/dist/server/actions/signInAction.js.map +1 -0
- package/dist/server/actions/signOutAction.d.ts +25 -0
- package/dist/server/actions/signOutAction.js +33 -0
- package/dist/server/actions/signOutAction.js.map +1 -0
- package/dist/server/actions/signUpAction.d.ts +35 -0
- package/dist/server/actions/signUpAction.js +52 -0
- package/dist/server/actions/signUpAction.js.map +1 -0
- package/dist/server/actions/updateUserProfileAction.d.ts +36 -0
- package/dist/server/actions/updateUserProfileAction.js +41 -0
- package/dist/server/actions/updateUserProfileAction.js.map +1 -0
- package/dist/utils/decorateConfigWithNextEnv.js +5 -1
- package/dist/utils/decorateConfigWithNextEnv.js.map +1 -1
- package/package.json +14 -4
|
@@ -19,15 +19,59 @@
|
|
|
19
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
20
|
import { I18nProvider, FlowProvider, UserProvider, ThemeProvider } from '@asgardeo/react';
|
|
21
21
|
import { useEffect, useMemo, useState } from 'react';
|
|
22
|
-
import { useRouter } from 'next/navigation';
|
|
22
|
+
import { useRouter, useSearchParams } from 'next/navigation';
|
|
23
23
|
import AsgardeoContext from './AsgardeoContext';
|
|
24
|
-
|
|
25
|
-
const AsgardeoClientProvider = ({ children, preferences, }) => {
|
|
24
|
+
const AsgardeoClientProvider = ({ baseUrl, children, signIn, signOut, signUp, handleOAuthCallback, preferences, isSignedIn, signInUrl, signUpUrl, user, userProfile, }) => {
|
|
26
25
|
const router = useRouter();
|
|
26
|
+
const searchParams = useSearchParams();
|
|
27
27
|
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
28
|
-
const [user, setUser] = useState(null);
|
|
29
28
|
const [isLoading, setIsLoading] = useState(true);
|
|
30
|
-
const [
|
|
29
|
+
const [_userProfile, setUserProfile] = useState(userProfile);
|
|
30
|
+
// Handle OAuth callback automatically
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
// Don't handle callback if already signed in
|
|
33
|
+
if (isSignedIn)
|
|
34
|
+
return;
|
|
35
|
+
const processOAuthCallback = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const code = searchParams.get('code');
|
|
38
|
+
const state = searchParams.get('state');
|
|
39
|
+
const sessionState = searchParams.get('session_state');
|
|
40
|
+
const error = searchParams.get('error');
|
|
41
|
+
const errorDescription = searchParams.get('error_description');
|
|
42
|
+
// Check for OAuth errors first
|
|
43
|
+
if (error) {
|
|
44
|
+
console.error('[AsgardeoClientProvider] OAuth error:', error, errorDescription);
|
|
45
|
+
// Redirect to sign-in page with error
|
|
46
|
+
router.push(`/signin?error=${encodeURIComponent(error)}&error_description=${encodeURIComponent(errorDescription || '')}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Handle OAuth callback if code and state are present
|
|
50
|
+
if (code && state) {
|
|
51
|
+
setIsLoading(true);
|
|
52
|
+
const result = await handleOAuthCallback(code, state, sessionState || undefined);
|
|
53
|
+
if (result.success) {
|
|
54
|
+
// Redirect to the success URL
|
|
55
|
+
if (result.redirectUrl) {
|
|
56
|
+
router.push(result.redirectUrl);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Refresh the page to update authentication state
|
|
60
|
+
window.location.reload();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
router.push(`/signin?error=authentication_failed&error_description=${encodeURIComponent(result.error || 'Authentication failed')}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('[AsgardeoClientProvider] Failed to handle OAuth callback:', error);
|
|
70
|
+
router.push('/signin?error=authentication_failed');
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
processOAuthCallback();
|
|
74
|
+
}, [searchParams, router, isSignedIn, handleOAuthCallback]);
|
|
31
75
|
useEffect(() => {
|
|
32
76
|
if (!preferences?.theme?.mode || preferences.theme.mode === 'system') {
|
|
33
77
|
setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
@@ -37,59 +81,81 @@ const AsgardeoClientProvider = ({ children, preferences, }) => {
|
|
|
37
81
|
}
|
|
38
82
|
}, [preferences?.theme?.mode]);
|
|
39
83
|
useEffect(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setUser(userData);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
setUser(null);
|
|
55
|
-
}
|
|
84
|
+
// Set loading to false when server has resolved authentication state
|
|
85
|
+
setIsLoading(false);
|
|
86
|
+
}, [isSignedIn, user]);
|
|
87
|
+
const handleSignIn = async (payload, request) => {
|
|
88
|
+
try {
|
|
89
|
+
const result = await signIn(payload, request);
|
|
90
|
+
// Redirect based flow URL is sent as `signInUrl` in the response.
|
|
91
|
+
if (result?.data?.signInUrl) {
|
|
92
|
+
router.push(result.data.signInUrl);
|
|
93
|
+
return;
|
|
56
94
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
// After the Embedded flow is successful, the URL to navigate next is sent as `afterSignInUrl` in the response.
|
|
96
|
+
if (result?.data?.afterSignInUrl) {
|
|
97
|
+
router.push(result.data.afterSignInUrl);
|
|
98
|
+
return;
|
|
60
99
|
}
|
|
61
|
-
|
|
62
|
-
|
|
100
|
+
if (result?.error) {
|
|
101
|
+
throw new Error(result.error);
|
|
63
102
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
103
|
+
return result?.data ?? result;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const handleSignUp = async (payload, request) => {
|
|
110
|
+
try {
|
|
111
|
+
const result = await signUp(payload, request);
|
|
112
|
+
// Redirect based flow URL is sent as `signUpUrl` in the response.
|
|
113
|
+
if (result?.data?.signUpUrl) {
|
|
114
|
+
router.push(result.data.signUpUrl);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// After the Embedded flow is successful, the URL to navigate next is sent as `afterSignUpUrl` in the response.
|
|
118
|
+
if (result?.data?.afterSignUpUrl) {
|
|
119
|
+
router.push(result.data.afterSignUpUrl);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (result?.error) {
|
|
123
|
+
throw new Error(result.error);
|
|
124
|
+
}
|
|
125
|
+
return result?.data ?? result;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const handleSignOut = async () => {
|
|
132
|
+
try {
|
|
133
|
+
const result = await signOut();
|
|
134
|
+
if (result?.data?.afterSignOutUrl) {
|
|
135
|
+
router.push(result.data.afterSignOutUrl);
|
|
136
|
+
return { redirected: true, location: result.data.afterSignOutUrl };
|
|
137
|
+
}
|
|
138
|
+
if (result?.error) {
|
|
139
|
+
throw new Error(result.error);
|
|
140
|
+
}
|
|
141
|
+
return result?.data ?? result;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw error;
|
|
78
145
|
}
|
|
79
|
-
return response.json();
|
|
80
146
|
};
|
|
81
147
|
const contextValue = useMemo(() => ({
|
|
148
|
+
baseUrl,
|
|
82
149
|
user,
|
|
83
150
|
isSignedIn,
|
|
84
151
|
isLoading,
|
|
85
|
-
signIn,
|
|
86
|
-
signOut:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, children: children }) }) }) }) }));
|
|
152
|
+
signIn: handleSignIn,
|
|
153
|
+
signOut: handleSignOut,
|
|
154
|
+
signUp: handleSignUp,
|
|
155
|
+
signInUrl,
|
|
156
|
+
signUpUrl,
|
|
157
|
+
}), [baseUrl, user, isSignedIn, isLoading, signInUrl, signUpUrl]);
|
|
158
|
+
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: userProfile, children: children }) }) }) }) }));
|
|
93
159
|
};
|
|
94
160
|
export default AsgardeoClientProvider;
|
|
95
161
|
//# sourceMappingURL=AsgardeoProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../../../src/client/contexts/Asgardeo/AsgardeoProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../../../src/client/contexts/Asgardeo/AsgardeoProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,CAAC;;AASb,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAAwB,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAC3D,OAAO,eAAuC,MAAM,mBAAmB,CAAC;AAgBxE,MAAM,sBAAsB,GAAuD,CAAC,EAClF,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,MAAM,EACN,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,IAAI,EACJ,WAAW,GACoC,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CA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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,IAAC,OAAO,EAAE,WAAW,YAAG,QAAQ,GAAgB,GAChD,GACD,GACH,GACU,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,17 +17,29 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export { default as AsgardeoProvider } from './server/AsgardeoProvider';
|
|
19
19
|
export * from './server/AsgardeoProvider';
|
|
20
|
+
export { default as useAsgardeo } from './client/contexts/Asgardeo/useAsgardeo';
|
|
21
|
+
export * from './client/contexts/Asgardeo/useAsgardeo';
|
|
20
22
|
export { default as isSignedIn } from './server/actions/isSignedIn';
|
|
23
|
+
export { default as handleOAuthCallback } from './server/actions/handleOAuthCallbackAction';
|
|
21
24
|
export { default as SignedIn } from './client/components/control/SignedIn/SignedIn';
|
|
22
25
|
export { SignedInProps } from './client/components/control/SignedIn/SignedIn';
|
|
23
26
|
export { default as SignedOut } from './client/components/control/SignedOut/SignedOut';
|
|
24
27
|
export { SignedOutProps } from './client/components/control/SignedOut/SignedOut';
|
|
25
28
|
export { default as SignInButton } from './client/components/actions/SignInButton/SignInButton';
|
|
26
29
|
export type { SignInButtonProps } from './client/components/actions/SignInButton/SignInButton';
|
|
30
|
+
export { default as SignUpButton } from './client/components/actions/SignUpButton/SignUpButton';
|
|
31
|
+
export type { SignUpButtonProps } from './client/components/actions/SignUpButton/SignUpButton';
|
|
27
32
|
export { default as SignIn } from './client/components/presentation/SignIn/SignIn';
|
|
28
33
|
export type { SignInProps } from './client/components/presentation/SignIn/SignIn';
|
|
29
34
|
export { default as SignOutButton } from './client/components/actions/SignOutButton/SignOutButton';
|
|
30
35
|
export type { SignOutButtonProps } from './client/components/actions/SignOutButton/SignOutButton';
|
|
31
36
|
export { default as User } from './client/components/presentation/User/User';
|
|
32
37
|
export type { UserProps } from './client/components/presentation/User/User';
|
|
38
|
+
export { default as SignUp } from './client/components/presentation/SignUp/SignUp';
|
|
39
|
+
export type { SignUpProps } from './client/components/presentation/SignUp/SignUp';
|
|
40
|
+
export { default as UserDropdown } from './client/components/presentation/UserDropdown/UserDropdown';
|
|
41
|
+
export type { UserDropdownProps } from './client/components/presentation/UserDropdown/UserDropdown';
|
|
42
|
+
export { default as UserProfile } from './client/components/presentation/UserProfile/UserProfile';
|
|
43
|
+
export type { UserProfileProps } from './client/components/presentation/UserProfile/UserProfile';
|
|
33
44
|
export { default as AsgardeoNext } from './AsgardeoNextClient';
|
|
45
|
+
export { default as asgardeoMiddleware } from './middleware/asgardeoMiddleware';
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,20 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export { default as AsgardeoProvider } from './server/AsgardeoProvider';
|
|
19
19
|
export * from './server/AsgardeoProvider';
|
|
20
|
+
export { default as useAsgardeo } from './client/contexts/Asgardeo/useAsgardeo';
|
|
21
|
+
export * from './client/contexts/Asgardeo/useAsgardeo';
|
|
20
22
|
export { default as isSignedIn } from './server/actions/isSignedIn';
|
|
23
|
+
export { default as handleOAuthCallback } from './server/actions/handleOAuthCallbackAction';
|
|
21
24
|
export { default as SignedIn } from './client/components/control/SignedIn/SignedIn';
|
|
22
25
|
export { default as SignedOut } from './client/components/control/SignedOut/SignedOut';
|
|
23
26
|
export { default as SignInButton } from './client/components/actions/SignInButton/SignInButton';
|
|
27
|
+
export { default as SignUpButton } from './client/components/actions/SignUpButton/SignUpButton';
|
|
24
28
|
export { default as SignIn } from './client/components/presentation/SignIn/SignIn';
|
|
25
29
|
export { default as SignOutButton } from './client/components/actions/SignOutButton/SignOutButton';
|
|
26
30
|
export { default as User } from './client/components/presentation/User/User';
|
|
31
|
+
export { default as SignUp } from './client/components/presentation/SignUp/SignUp';
|
|
32
|
+
export { default as UserDropdown } from './client/components/presentation/UserDropdown/UserDropdown';
|
|
33
|
+
export { default as UserProfile } from './client/components/presentation/UserProfile/UserProfile';
|
|
27
34
|
export { default as AsgardeoNext } from './AsgardeoNextClient';
|
|
35
|
+
export { default as asgardeoMiddleware } from './middleware/asgardeoMiddleware';
|
|
28
36
|
//# 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,+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"}
|
|
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,WAAW,EAAC,MAAM,wCAAwC,CAAC;AAC9E,cAAc,wCAAwC,CAAC;AAEvD,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,4CAA4C,CAAC;AAE1F,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,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,MAAM,EAAC,MAAM,gDAAgD,CAAC;AAGjF,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,4DAA4D,CAAC;AAGnG,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,0DAA0D,CAAC;AAGhG,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { NextRequest, NextResponse } from 'next/server';
|
|
19
|
+
import { AsgardeoNextConfig } from '../models/config';
|
|
20
|
+
export interface AsgardeoMiddlewareOptions extends Partial<AsgardeoNextConfig> {
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
}
|
|
23
|
+
type AsgardeoAuth = {
|
|
24
|
+
protect: (options?: {
|
|
25
|
+
redirect?: string;
|
|
26
|
+
}) => Promise<NextResponse | void>;
|
|
27
|
+
isSignedIn: () => Promise<boolean>;
|
|
28
|
+
getUser: () => Promise<any | null>;
|
|
29
|
+
redirectToSignIn: (afterSignInUrl?: string) => NextResponse;
|
|
30
|
+
};
|
|
31
|
+
type AsgardeoMiddlewareHandler = (auth: AsgardeoAuth, req: NextRequest) => Promise<NextResponse | void> | NextResponse | void;
|
|
32
|
+
/**
|
|
33
|
+
* Asgardeo middleware that integrates authentication into your Next.js application.
|
|
34
|
+
* Similar to Clerk's clerkMiddleware pattern.
|
|
35
|
+
*
|
|
36
|
+
* @param handler - Optional handler function to customize middleware behavior
|
|
37
|
+
* @param options - Configuration options for the middleware
|
|
38
|
+
* @returns Next.js middleware function
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // middleware.ts
|
|
43
|
+
* import { asgardeoMiddleware } from '@asgardeo/nextjs';
|
|
44
|
+
*
|
|
45
|
+
* export default asgardeoMiddleware();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // With protection
|
|
51
|
+
* import { asgardeoMiddleware, createRouteMatcher } from '@asgardeo/nextjs';
|
|
52
|
+
*
|
|
53
|
+
* const isProtectedRoute = createRouteMatcher(['/dashboard(.*)']);
|
|
54
|
+
*
|
|
55
|
+
* export default asgardeoMiddleware(async (auth, req) => {
|
|
56
|
+
* if (isProtectedRoute(req)) {
|
|
57
|
+
* await auth.protect();
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const asgardeoMiddleware: (handler?: AsgardeoMiddlewareHandler, options?: AsgardeoMiddlewareOptions | ((req: NextRequest) => AsgardeoMiddlewareOptions)) => ((request: NextRequest) => Promise<NextResponse>);
|
|
63
|
+
export default asgardeoMiddleware;
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { NextResponse } from 'next/server';
|
|
19
|
+
import AsgardeoNextClient from '../AsgardeoNextClient';
|
|
20
|
+
/**
|
|
21
|
+
* Asgardeo middleware that integrates authentication into your Next.js application.
|
|
22
|
+
* Similar to Clerk's clerkMiddleware pattern.
|
|
23
|
+
*
|
|
24
|
+
* @param handler - Optional handler function to customize middleware behavior
|
|
25
|
+
* @param options - Configuration options for the middleware
|
|
26
|
+
* @returns Next.js middleware function
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // middleware.ts
|
|
31
|
+
* import { asgardeoMiddleware } from '@asgardeo/nextjs';
|
|
32
|
+
*
|
|
33
|
+
* export default asgardeoMiddleware();
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // With protection
|
|
39
|
+
* import { asgardeoMiddleware, createRouteMatcher } from '@asgardeo/nextjs';
|
|
40
|
+
*
|
|
41
|
+
* const isProtectedRoute = createRouteMatcher(['/dashboard(.*)']);
|
|
42
|
+
*
|
|
43
|
+
* export default asgardeoMiddleware(async (auth, req) => {
|
|
44
|
+
* if (isProtectedRoute(req)) {
|
|
45
|
+
* await auth.protect();
|
|
46
|
+
* }
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
const asgardeoMiddleware = (handler, options) => {
|
|
51
|
+
return async (request) => {
|
|
52
|
+
// Resolve options - can be static or dynamic based on request
|
|
53
|
+
const resolvedOptions = typeof options === 'function' ? options(request) : options || {};
|
|
54
|
+
const asgardeoClient = AsgardeoNextClient.getInstance();
|
|
55
|
+
// // Initialize client if not already done
|
|
56
|
+
// if (!asgardeoClient.isInitialized && resolvedOptions) {
|
|
57
|
+
// asgardeoClient.initialize(resolvedOptions);
|
|
58
|
+
// }
|
|
59
|
+
// // Debug logging
|
|
60
|
+
// if (resolvedOptions.debug) {
|
|
61
|
+
// console.log(`[Asgardeo Middleware] Processing request: ${request.nextUrl.pathname}`);
|
|
62
|
+
// }
|
|
63
|
+
// // Handle auth API routes automatically
|
|
64
|
+
// if (request.nextUrl.pathname.startsWith('/api/auth/asgardeo')) {
|
|
65
|
+
// if (resolvedOptions.debug) {
|
|
66
|
+
// console.log(`[Asgardeo Middleware] Handling auth route: ${request.nextUrl.pathname}`);
|
|
67
|
+
// }
|
|
68
|
+
// return await asgardeoClient.handleAuthRequest(request);
|
|
69
|
+
// }
|
|
70
|
+
// // Create auth object for the handler
|
|
71
|
+
// const auth: AsgardeoAuth = {
|
|
72
|
+
// protect: async (options?: {redirect?: string}) => {
|
|
73
|
+
// const isSignedIn = await asgardeoClient.isSignedIn(request);
|
|
74
|
+
// if (!isSignedIn) {
|
|
75
|
+
// const afterSignInUrl = options?.redirect || '/api/auth/asgardeo/signin';
|
|
76
|
+
// return NextResponse.redirect(new URL(afterSignInUrl, request.url));
|
|
77
|
+
// }
|
|
78
|
+
// },
|
|
79
|
+
// isSignedIn: async () => {
|
|
80
|
+
// return await asgardeoClient.isSignedIn(request);
|
|
81
|
+
// },
|
|
82
|
+
// getUser: async () => {
|
|
83
|
+
// return await asgardeoClient.getUser(request);
|
|
84
|
+
// },
|
|
85
|
+
// redirectToSignIn: (afterSignInUrl?: string) => {
|
|
86
|
+
// const signInUrl = afterSignInUrl || '/api/auth/asgardeo/signin';
|
|
87
|
+
// return NextResponse.redirect(new URL(signInUrl, request.url));
|
|
88
|
+
// },
|
|
89
|
+
// };
|
|
90
|
+
// // Execute user-provided handler if present
|
|
91
|
+
// let handlerResponse: NextResponse | void;
|
|
92
|
+
// if (handler) {
|
|
93
|
+
// handlerResponse = await handler(auth, request);
|
|
94
|
+
// }
|
|
95
|
+
// // If handler returned a response, use it
|
|
96
|
+
// if (handlerResponse) {
|
|
97
|
+
// return handlerResponse;
|
|
98
|
+
// }
|
|
99
|
+
// // Otherwise, continue with default behavior
|
|
100
|
+
// const response = NextResponse.next();
|
|
101
|
+
// // Add authentication context to response headers
|
|
102
|
+
// const isSignedIn = await asgardeoClient.isSignedIn(request);
|
|
103
|
+
// if (isSignedIn) {
|
|
104
|
+
// response.headers.set('x-asgardeo-authenticated', 'true');
|
|
105
|
+
// const user = await asgardeoClient.getUser(request);
|
|
106
|
+
// if (user?.sub) {
|
|
107
|
+
// response.headers.set('x-asgardeo-user-id', user.sub);
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
// return response;
|
|
111
|
+
return NextResponse.next();
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export default asgardeoMiddleware;
|
|
115
|
+
//# sourceMappingURL=asgardeoMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asgardeoMiddleware.js","sourceRoot":"","sources":["../../src/middleware/asgardeoMiddleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAc,YAAY,EAAC,MAAM,aAAa,CAAC;AACtD,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAmBvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,kBAAkB,GAAG,CACzB,OAAmC,EACnC,OAAuF,EACpC,EAAE;IACrD,OAAO,KAAK,EAAE,OAAoB,EAAyB,EAAE;QAC3D,8DAA8D;QAC9D,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;QAEzF,MAAM,cAAc,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAExD,2CAA2C;QAC3C,0DAA0D;QAC1D,gDAAgD;QAChD,IAAI;QAEJ,mBAAmB;QACnB,+BAA+B;QAC/B,0FAA0F;QAC1F,IAAI;QAEJ,0CAA0C;QAC1C,mEAAmE;QACnE,iCAAiC;QACjC,6FAA6F;QAC7F,MAAM;QACN,4DAA4D;QAC5D,IAAI;QAEJ,wCAAwC;QACxC,+BAA+B;QAC/B,wDAAwD;QACxD,mEAAmE;QACnE,yBAAyB;QACzB,iFAAiF;QACjF,4EAA4E;QAC5E,QAAQ;QACR,OAAO;QAEP,8BAA8B;QAC9B,uDAAuD;QACvD,OAAO;QAEP,2BAA2B;QAC3B,oDAAoD;QACpD,OAAO;QAEP,qDAAqD;QACrD,uEAAuE;QACvE,qEAAqE;QACrE,OAAO;QACP,KAAK;QAEL,8CAA8C;QAC9C,4CAA4C;QAC5C,iBAAiB;QACjB,oDAAoD;QACpD,IAAI;QAEJ,4CAA4C;QAC5C,yBAAyB;QACzB,4BAA4B;QAC5B,IAAI;QAEJ,+CAA+C;QAC/C,wCAAwC;QAExC,oDAAoD;QACpD,+DAA+D;QAC/D,oBAAoB;QACpB,8DAA8D;QAC9D,wDAAwD;QACxD,qBAAqB;QACrB,4DAA4D;QAC5D,MAAM;QACN,IAAI;QAEJ,mBAAmB;QAEnB,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -16,20 +16,23 @@
|
|
|
16
16
|
* under the License.
|
|
17
17
|
*/
|
|
18
18
|
import { FC, PropsWithChildren } from 'react';
|
|
19
|
-
import {
|
|
19
|
+
import { AsgardeoProviderProps } from '@asgardeo/react';
|
|
20
20
|
/**
|
|
21
21
|
* Props interface of {@link AsgardeoServerProvider}
|
|
22
22
|
*/
|
|
23
|
-
export type AsgardeoServerProviderProps =
|
|
23
|
+
export type AsgardeoServerProviderProps = Partial<AsgardeoProviderProps> & {
|
|
24
|
+
clientSecret?: string;
|
|
25
|
+
};
|
|
24
26
|
/**
|
|
25
27
|
* Server-side provider component for Asgardeo authentication.
|
|
26
28
|
* Wraps the client-side provider and handles server-side authentication logic.
|
|
29
|
+
* Uses the singleton AsgardeoNextClient instance for consistent authentication state.
|
|
27
30
|
*
|
|
28
31
|
* @param props - Props injected into the component.
|
|
29
32
|
*
|
|
30
33
|
* @example
|
|
31
34
|
* ```tsx
|
|
32
|
-
* <AsgardeoServerProvider>
|
|
35
|
+
* <AsgardeoServerProvider config={asgardeoConfig}>
|
|
33
36
|
* <YourApp />
|
|
34
37
|
* </AsgardeoServerProvider>
|
|
35
38
|
* ```
|
|
@@ -1,20 +1,59 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AsgardeoRuntimeError } from '@asgardeo/node';
|
|
2
3
|
import AsgardeoClientProvider from '../client/contexts/Asgardeo/AsgardeoProvider';
|
|
4
|
+
import AsgardeoNextClient from '../AsgardeoNextClient';
|
|
5
|
+
import signInAction from './actions/signInAction';
|
|
6
|
+
import signOutAction from './actions/signOutAction';
|
|
7
|
+
import isSignedIn from './actions/isSignedIn';
|
|
8
|
+
import getUserAction from './actions/getUserAction';
|
|
9
|
+
import getSessionId from './actions/getSessionId';
|
|
10
|
+
import getUserProfileAction from './actions/getUserProfileAction';
|
|
11
|
+
import signUpAction from './actions/signUpAction';
|
|
12
|
+
import handleOAuthCallbackAction from './actions/handleOAuthCallbackAction';
|
|
3
13
|
/**
|
|
4
14
|
* Server-side provider component for Asgardeo authentication.
|
|
5
15
|
* Wraps the client-side provider and handles server-side authentication logic.
|
|
16
|
+
* Uses the singleton AsgardeoNextClient instance for consistent authentication state.
|
|
6
17
|
*
|
|
7
18
|
* @param props - Props injected into the component.
|
|
8
19
|
*
|
|
9
20
|
* @example
|
|
10
21
|
* ```tsx
|
|
11
|
-
* <AsgardeoServerProvider>
|
|
22
|
+
* <AsgardeoServerProvider config={asgardeoConfig}>
|
|
12
23
|
* <YourApp />
|
|
13
24
|
* </AsgardeoServerProvider>
|
|
14
25
|
* ```
|
|
15
26
|
*
|
|
16
27
|
* @returns AsgardeoServerProvider component.
|
|
17
28
|
*/
|
|
18
|
-
const AsgardeoServerProvider = ({ children, }) =>
|
|
29
|
+
const AsgardeoServerProvider = async ({ children, afterSignInUrl, afterSignOutUrl, ..._config }) => {
|
|
30
|
+
const asgardeoClient = AsgardeoNextClient.getInstance();
|
|
31
|
+
let config = {};
|
|
32
|
+
try {
|
|
33
|
+
await asgardeoClient.initialize(_config);
|
|
34
|
+
config = await asgardeoClient.getConfiguration();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new AsgardeoRuntimeError(`Failed to initialize Asgardeo client: ${error?.toString()}`, 'next-ConfigurationError-001', 'next', 'An error occurred while initializing the Asgardeo client. Please check your configuration.');
|
|
38
|
+
}
|
|
39
|
+
if (!asgardeoClient.isInitialized) {
|
|
40
|
+
return _jsx(_Fragment, {});
|
|
41
|
+
}
|
|
42
|
+
const sessionId = (await getSessionId());
|
|
43
|
+
const _isSignedIn = await isSignedIn(sessionId);
|
|
44
|
+
let user = {};
|
|
45
|
+
let userProfile = {
|
|
46
|
+
schemas: [],
|
|
47
|
+
profile: {},
|
|
48
|
+
flattenedProfile: {},
|
|
49
|
+
};
|
|
50
|
+
if (_isSignedIn) {
|
|
51
|
+
const userResponse = await getUserAction(sessionId);
|
|
52
|
+
const userProfileResponse = await getUserProfileAction(sessionId);
|
|
53
|
+
user = userResponse.data?.user || {};
|
|
54
|
+
userProfile = userProfileResponse.data?.userProfile;
|
|
55
|
+
}
|
|
56
|
+
return (_jsx(AsgardeoClientProvider, { baseUrl: config.baseUrl, signIn: signInAction, signOut: signOutAction, signUp: signUpAction, handleOAuthCallback: handleOAuthCallbackAction, signInUrl: config.signInUrl, signUpUrl: config.signUpUrl, preferences: config.preferences, clientId: config.clientId, user: user, userProfile: userProfile, isSignedIn: _isSignedIn, children: children }));
|
|
57
|
+
};
|
|
19
58
|
export default AsgardeoServerProvider;
|
|
20
59
|
//# sourceMappingURL=AsgardeoProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../src/server/AsgardeoProvider.tsx"],"names":[],"mappings":";AAmBA,OAAO,sBAAqD,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"AsgardeoProvider.js","sourceRoot":"","sources":["../../src/server/AsgardeoProvider.tsx"],"names":[],"mappings":";AAmBA,OAAO,EAAC,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AACvE,OAAO,sBAAqD,MA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AE;QACX,gBAAgB,EAAE,EAAE;KACrB,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,mBAAmB,GAAG,MAAM,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAElE,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACrC,WAAW,GAAG,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC;IACtD,CAAC;IAED,OAAO,CACL,KAAC,sBAAsB,IACrB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,YAAY,EACpB,mBAAmB,EAAE,yBAAyB,EAC9C,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,WAAW,YAEtB,QAAQ,GACc,CAC1B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { headers } from 'next/headers';
|
|
3
|
+
const getClientOrigin = async () => {
|
|
4
|
+
const headersList = await headers();
|
|
5
|
+
const host = headersList.get('host');
|
|
6
|
+
const protocol = headersList.get('x-forwarded-proto') ?? 'http';
|
|
7
|
+
return `${protocol}://${host}`;
|
|
8
|
+
};
|
|
9
|
+
export default getClientOrigin;
|
|
10
|
+
//# sourceMappingURL=getClientOrigin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientOrigin.js","sourceRoot":"","sources":["../../../src/server/actions/getClientOrigin.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;IACjC,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,MAAM,CAAC;IAChE,OAAO,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;AACjC,CAAC,CAAC;AAEF,eAAe,eAAe,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
|
+
/**
|
|
19
|
+
* Server action to get the current user.
|
|
20
|
+
* Returns the user profile if signed in.
|
|
21
|
+
*/
|
|
22
|
+
declare const getUserAction: (sessionId: string) => Promise<{
|
|
23
|
+
success: boolean;
|
|
24
|
+
data: {
|
|
25
|
+
user: import("@asgardeo/node").User;
|
|
26
|
+
};
|
|
27
|
+
error: null;
|
|
28
|
+
} | {
|
|
29
|
+
success: boolean;
|
|
30
|
+
data: {
|
|
31
|
+
user: null;
|
|
32
|
+
};
|
|
33
|
+
error: string;
|
|
34
|
+
}>;
|
|
35
|
+
export default getUserAction;
|