Error: Cannot access Cognito.length on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
import { runWithAmplifyServerContext } from "@/utils/amplify-server-utils";
import { getCurrentUser } from "aws-amplify/auth/server";
import { cookies } from "next/headers";
export default async function Dashboard(req:Request) {
let user = null;
try {
user = await runWithAmplifyServerContext({
nextServerContext:{
cookies: cookies
},
operation: async (contextSpec) => {
return await getCurrentUser(contextSpec);
},
});
console.log(user);
}catch(err) {
console.error(err);
}
return <p>Dashboard Page</p>;
New contributor
Alok Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.