e.userData is undefined
Unanswered
Northeast Congo Lion posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Weird error occurs when I click a Next.Link element. It says "e.userData not found". userData is a variable used in my middleware and another similar layer that is used elsewhere. It's also used as a prop in a page that shouldn't be relevant as the link leads neither to nor from it.
This error doesn't occur on my local machine, only with the built version when it's deployed. (of course, this is a problem plaguing my Production server). Any idea what might be going on here?
https://i.gyazo.com/1ac10357736e02f1194911da30492bdc.png
https://i.gyazo.com/b295a11a64e5abc99e7d2f6b70860ec1.png
it also goes away when I refresh. So click link -> error-> refresh -> all good
This error doesn't occur on my local machine, only with the built version when it's deployed. (of course, this is a problem plaguing my Production server). Any idea what might be going on here?
https://i.gyazo.com/1ac10357736e02f1194911da30492bdc.png
https://i.gyazo.com/b295a11a64e5abc99e7d2f6b70860ec1.png
it also goes away when I refresh. So click link -> error-> refresh -> all good
52 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Spectacled bear
userdata property of an object, but the property does not exist
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Well, why is it being created in my local version and not in the built version?
And why is it fine when I refresh
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Spectacled bear
Different server configurations or version?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
cna yuo give all details as to where and how you are deploying
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Sure
Again, not 100% sure what code is causing this problem
so I'll show what I can as far as code
I'm deploying using SST to AWS
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
also you should share all relevant code around userData
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Yup hang on am doing so
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Spectacled bear
The e.userData not found error is occurring because of a difference in the way that serverless applications are handled by AWS compared to traditional web applications
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
thanks, chatgpt
if (props.userData.tier != "free" && linksList.length > 4){
linksList = [<Link href="/links" className={styles.primaryButton} key="0">Manage Links</Link>]
newLinkButton = <></>
}
@Barbary Lion this is the most "Suspect code" here
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Spectacled bear
What
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
I say that because this is the only time there's an ".userData" anywhere
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Spectacled bear
uhm
![:verysad:](https://cdn.discordapp.com/emojis/809129075582173196.png)
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
But what's weird is that it's erroring every time a Link is clicked, not just the code that's running this page
in a diff part of the code we have this:
let userData = resultVal.split("#")
if (userData.length === 3){
emailVerified = userData[2] === "true"
}
let resultVal:string = ""
if (result.val){
//validate the cookie
validCookie = true
resultVal = result.val as string
}
also have this code
export async function userFromCookies(req:any):Promise<User|null>{
const userData = await verifyAuth(req);
if (!userData) {
console.log("No user data, request: ", req)
return null
}
let userString = userData.val as string;
let userID:number = parseInt(userString.split("#")[1])
let userName = parseInt(userString.split("#")[0])
let prisma = new PrismaClient()
//get user data from the database
let foundUser = await prisma.user.findUnique({
where: {
id: userID
}
})
await prisma.$disconnect()
return foundUser
}
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
in the if statement add to the beginning "props.userData &&", same with teh second block of code below
also check out phind.com it is the best programming chatbot I've used, better than gpt4.
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Is it possible to have code from one part/page of your application erroring on a diff page
is SpeedyFriend67 phind.com?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
nope probably chatgpt 3.5 which sucks
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Fair nuff
So I modified some code
the error message changed after a deploy
so now I can narrow it down a little, I think, though there's still another error
it's using "o" now, but similar error
so yeah. Now having 2 issues. Problem 1:
e.userSerialized is undefined (I think this is happening in a react.useState thing)
e.userSerialized is undefined (I think this is happening in a react.useState thing)
Problem 2: Totally unknown location saying "o" is undefined
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
u should disable bundling and minification for production build so u can set breakpoints and read the code in production
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
That's probably a good idea. Any idea how to do that in SST?
Let me ask in SST
seems to be coming from any case where a props object is used in a react.useState
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Yeah this is very weird... props aren't being received at all when navigating with Link
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
you mean a state variable is passed in as a prop?
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Hang on, let me give an example
userDataSerialized is passed in via props in this example
let imgWidth = 200
if (props.userDataSerialized){
imgWidth = props.userDataSerialized.imageWidth
}
let [imageWidth, setImageWidth] = React.useState(imgWidth)
this will behave as if imgWidth is 200
there's a property called "authorized" that's handled a similar way
if (!authorized){
return (<>
{genHead("Unauthorized", "You are not authorized to access the controls page.")}
<main className={`${styles.main} ${inter.className}`}>
<h1>You are not authorized to access the controls page.</h1>
</main>
</>)
}
This causes the page to show this message every time unless refresh is used.
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
how is authorized handle in a similar way
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
const {authorized, id, controllers} = props
basically something about the props is what's going on.
if I were to suspect, it's that
getServerSideProps
is not being called when you click a Linkbut only on built versions for some reason
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Northeast Congo LionOP
Fixed.
It's a problem with 13.4 it seems