I'm trying to make an user-authenticated GraphQL request on the serverside in getServerSideProps using AWS Amplify and Next JS.
Users in my AWS Database can only access the data if they are the owner of the document.
The error I get from this is "No current user"... (which is being logged on the server). The problem is, that I need the user available in the getServerSideProps, so I can make the authenticated request happen.
Here is the code I currently have
index.tsx:
import Amplify, { API, graphqlOperation, withSSRContext } from "aws-amplify";
import config from "../aws-exports";
Amplify.configure({ ...config, ssr: true });
function Index({ bankAccounts }: { bankAccounts: BankAccount[] }) {
return (
...stuff...
);
}
index.tsx (getServerSideProps):
export const getServerSideProps: GetServerSideProps = async (context) => {
const { API } = withSSRContext(context);
const result = (await API.graphql({
query: listBankAccounts,
})) as {
data: ListBankAccountsQuery;
errors: any[];
};
if (!result.errors) {
return {
props: {
bankAccounts: result.data.listBankAccounts.items,
},
};
}
return {
props: {
bankAccounts: [],
},
};
};
I would greatly appreciate any help or advice you could offer!