@asgardeo/nextjs
Version:
Next.js implementation of Asgardeo JavaScript SDK.
56 lines • 2.24 kB
JavaScript
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { BaseUserProfile, useUser } from '@asgardeo/react';
import useAsgardeo from '../../../contexts/Asgardeo/useAsgardeo';
import getSessionId from '../../../../server/actions/getSessionId';
/**
* UserProfile component displays the authenticated user's profile information in a
* structured and styled format. It shows user details such as display name, email,
* username, and other available profile information from Asgardeo.
*
* This component is the React-specific implementation that uses the BaseUserProfile
* and automatically retrieves the user data from Asgardeo context if not provided.
*
* @example
* ```tsx
* // Basic usage - will use user from Asgardeo context
* <UserProfile />
*
* // With explicit user data
* <UserProfile user={specificUser} />
*
* // With card layout and custom fallback
* <UserProfile
* cardLayout={true}
* fallback={<div>Please sign in to view your profile</div>}
* />
* ```
*/
const UserProfile = ({ ...rest }) => {
const { baseUrl } = useAsgardeo();
const { profile, flattenedProfile, schemas, onUpdateProfile, updateProfile } = useUser();
const handleProfileUpdate = async (payload) => {
const result = await updateProfile(payload, (await getSessionId()));
onUpdateProfile(result?.data?.user);
};
return (_jsx(BaseUserProfile, { profile: profile, flattenedProfile: flattenedProfile, schemas: schemas, onUpdate: handleProfileUpdate, ...rest }));
};
export default UserProfile;
//# sourceMappingURL=UserProfile.js.map