Skip to content

Commit 5f003f0

Browse files
committed
chore(nextjs): integrate organization context into Asgardeo components and update Dashboard pages
1 parent def1d47 commit 5f003f0

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

packages/nextjs/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
export {default as AsgardeoProvider} from './server/AsgardeoProvider';
2020
export * from './server/AsgardeoProvider';
2121

22+
export {default as useAsgardeo} from './client/contexts/Asgardeo/useAsgardeo';
23+
export * from './client/contexts/Asgardeo/useAsgardeo';
24+
2225
export {default as isSignedIn} from './server/actions/isSignedIn';
2326

2427
export {default as SignedIn} from './client/components/control/SignedIn/SignedIn';

packages/react/src/contexts/Asgardeo/AsgardeoContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import {Context, createContext} from 'react';
20+
import {Organization} from '@asgardeo/browser';
2021

2122
/**
2223
* Props interface of {@link AsgardeoContext}
@@ -53,6 +54,7 @@ export type AsgardeoContextProps = {
5354
*/
5455
signUp: any;
5556
user: any;
57+
organization: Organization;
5658
};
5759

5860
/**
@@ -65,6 +67,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
6567
isInitialized: false,
6668
isLoading: true,
6769
isSignedIn: false,
70+
organization: null,
6871
signIn: null,
6972
signOut: null,
7073
signUp: null,

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
237237
isInitialized: isInitializedSync,
238238
isLoading: asgardeo.isLoading(),
239239
isSignedIn: isSignedInSync,
240+
organization: currentOrganization,
240241
signIn,
241242
signOut,
242243
signUp,

samples/teamspace-nextjs/app/dashboard/page.tsx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,10 @@ import {Users, MessageSquare, Calendar, FileText, TrendingUp, Clock, CheckCircle
77
import {redirect} from 'next/navigation';
88
import {useEffect} from 'react';
99
import {Header} from '@/components/Header/Header';
10+
import {useAsgardeo, User} from '@asgardeo/nextjs';
1011

1112
export default function DashboardPage() {
12-
const {user, currentOrg, isAuthenticated, isLoading} = {
13-
user: null, // Replace with actual user data fetching logic
14-
currentOrg: null, // Replace with actual organization data fetching logic
15-
isAuthenticated: false, // Replace with actual authentication check
16-
isLoading: true, // Replace with actual loading state
17-
};
18-
19-
useEffect(() => {
20-
if (!isLoading && !isAuthenticated) {
21-
redirect('/');
22-
}
23-
}, [isAuthenticated, isLoading]);
24-
25-
if (isLoading) {
26-
return <div className="flex items-center justify-center min-h-screen">Loading...</div>;
27-
}
28-
29-
if (!isAuthenticated) {
30-
return null;
31-
}
13+
const {organization, user} = useAsgardeo();
3214

3315
const stats = [
3416
{
@@ -40,7 +22,7 @@ export default function DashboardPage() {
4022
},
4123
{
4224
name: 'Team Members',
43-
value: currentOrg?.memberCount.toString() || '0',
25+
value: '0',
4426
change: '+5.4%',
4527
changeType: 'positive' as const,
4628
icon: Users,
@@ -122,8 +104,19 @@ export default function DashboardPage() {
122104

123105
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
124106
<div className="mb-8">
125-
<h1 className="text-3xl font-bold text-gray-900">Welcome back {user?.name}!</h1>
126-
<p className="text-gray-600 mt-2">Here's what's happening with {currentOrg?.name} today.</p>
107+
<h1 className="text-3xl font-bold text-gray-900">
108+
Welcome back{' '}
109+
<User>
110+
{user => (
111+
<span>
112+
{user?.givenName || user?.name?.givenName || user?.given_name}{' '}
113+
{user?.name?.familyName || user?.familyName || user?.family_name}
114+
</span>
115+
)}
116+
</User>
117+
!
118+
</h1>
119+
<p className="text-gray-600 mt-2">Here's what's happening with {organization?.orgHandle} today.</p>
127120
</div>
128121

129122
{/* Stats Grid */}

samples/teamspace-react/src/pages/Dashboard.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {User} from '@asgardeo/react';
2-
import {useApp} from '../App';
1+
import {User, useAsgardeo} from '@asgardeo/react';
32
import {Users, MessageSquare, Calendar, FileText, TrendingUp, Clock, CheckCircle2, AlertCircle} from 'lucide-react';
43

54
export default function Dashboard() {
6-
const {currentOrg} = useApp();
5+
const {organization} = useAsgardeo();
76

87
const stats = [
98
{
@@ -15,7 +14,7 @@ export default function Dashboard() {
1514
},
1615
{
1716
name: 'Team Members',
18-
value: currentOrg?.memberCount.toString() || '0',
17+
value: '0',
1918
change: '+5.4%',
2019
changeType: 'positive',
2120
icon: Users,
@@ -108,7 +107,7 @@ export default function Dashboard() {
108107
!
109108
</h1>
110109

111-
<p className="text-gray-600 mt-2">Here's what's happening with {currentOrg?.name} today.</p>
110+
<p className="text-gray-600 mt-2">Here's what's happening with @{organization?.orgHandle} today.</p>
112111
</div>
113112

114113
{/* Stats Grid */}

0 commit comments

Comments
 (0)