I've hit a roadblock with an issue I can't seem to solve. I'm exporting a function that is supposed to provide the current authenticated user object, if available. I then use this user object to determine whether to add a navigation link. Despite multiple attempts to fix the reference, the error persists.
This is the function definition located at @/app/hooks/use-auth-user.ts
'use client';
import {
fetchAuthSession,
fetchUserAttributes,
getCurrentUser,
} from 'aws-amplify/auth';
import { useEffect, useState } from 'react';
export default function UseAuthUser() {
const [user, setUser] = useState<Record<string, any>>();
useEffect(() => {
async function getUser() {
const session = await fetchAuthSession();
if (!session.tokens) {
return;
}
const user = {
...(await getCurrentUser()),
...(await fetchUserAttributes()),
isAdmin: false,
};
const groups = session.tokens.accessToken.payload['cognito:groups'];
// @ts-ignore
user.isAdmin = Boolean(groups && groups.includes('administrators'));
setUser(user);
}
getUser();
}, []);
return user;
}
And here is where I am referencing it from, located at @/app/lib/menus.ts
import UseAuthUser from '@/app/hooks/use-auth-user';
export function getResourceMenu(): Menu {
const user = UseAuthUser();
let links: Menu = [
{ name: 'Privacy Policy', href: '/privacy' },
{ name: 'Terms & Conditions', href: '/terms-and-conditions' },
{ name: 'Member Portal', href: '/auth/login' },
];
if (user) {
links.push({ name: 'Dashboard', href: '/dashboard' });
}
return links;
}
I have provided a screenshot of the error message below:
Error: (0 , _app_hooks_use_auth_user__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
https://i.sstatic.net/VTAkvith.png
I would greatly appreciate any insights on where I might be making a mistake because clearly, there is one.