#StackBounty: #reactjs #graphql #next.js #aws-amplify #aws-appsync AWS Amplify and Next.JS with GraphQL Server Error No current user fr…

Bounty: 200

I’m having trouble accessing data from Amplify’s API Graphql, and it keeps returning

Server Error
Error: No current user

I’ve been following this tutorial: https://youtu.be/13nYLmjZ0Ys?t=2292

I know I’m signed into Amplify because if I go into different pages, I can grab user Auth and I can even display the SignOut button. But for whatever reason, I’m not sure why I’m getting this error

import { API } from "aws-amplify";
import { useRouter } from "next/router";
import { listActivations, getActivation } from "../../graphql/queries";

const Activation = ({ activation }) => {
  const router = useRouter();
  if (router.isFallback) {
    return <div>Loading</div>;
  }
  return <div>{activation.title}</div>;
};
export default Activation;

export async function getStaticPaths() {
  const SSR = withSSRContext();
  console.log("static paths");
  const activationData = await SSR.API.graphql({
    query: listActivations,
  });
  console.log("activationData", activationData);
  const paths = activationData.data.listActivations.items.map((activation) => ({
    params: { id: activation.id },
  }));
  return {
    paths,
    fallback: true,
  };
}

export async function getStaticProps({ params }) {
  const SSR = withSSRContext(); // added SSR, but still getting error
  console.log("static props");
  const { id } = params;
  const activationData = await SSR.API.graphql({
    query: getActivation,
    variables: { id },
  });
  return {
    props: {
      activation: activationData.data.getActivation,
    },
  };
}

The console log static paths appears, and then after that, I get errors.

Do you think it has anything to do with my GraphQL schema?

type User @model @auth(rules: [{ allow: owner, ownerField: "username" }]) {
  id: ID!
  username: String!
  email: String!
  userType: UserType
}

type Activation
  @model
  @key(
    name: "activationsByStudentId"
    fields: ["student"]
    queryField: "activationsByStudentId"
  )
  @auth(
    rules: [
      { allow: groups, groups: ["Admin"] }
      { allow: owner }
      {
        allow: owner
        ownerField: "studentId"
        operations: [create, update, delete]
      }
      { allow: private, operations: [read] }
      { allow: public, operations: [read] }
    ]
  ) {
  id: ID!
  studentId: ID!
  title: String!
  student: Student @connection(fields: ["studentId"])
  teachers: [TeachersActivations] @connection(name: "ActivationTeachers")
}

Edit: I’ve also added User model to see if this could be a cause too.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.