nole
nole
WWasp
Created by nole on 5/10/2025 in #🙋questions
How do you access a user's identity through a query?
Context Myapp is configured to use usernameAndPassword auth method.
app TodoApp {
wasp: {
version: "^0.16.3"
},
title: "TodoApp",
auth: {
// Tells Wasp which entity to use for storing users.
userEntity: User,
methods: {
// Enable username and password auth.
usernameAndPassword: {}
},
// We'll see how this is used in a bit.
onAuthFailedRedirectTo: "/login"
}
}
app TodoApp {
wasp: {
version: "^0.16.3"
},
title: "TodoApp",
auth: {
// Tells Wasp which entity to use for storing users.
userEntity: User,
methods: {
// Enable username and password auth.
usernameAndPassword: {}
},
// We'll see how this is used in a bit.
onAuthFailedRedirectTo: "/login"
}
}
s I am trying to show an entity based off of a parameter in the URL 📄 main.wasp
// Wasp: `version: "^0.16.3"`
route UserPagesRoute { path: "/pages/:username", to: UserPages }
page UserPages {
component: import { UserPages } from "@src/UserPages"
}
// Wasp: `version: "^0.16.3"`
route UserPagesRoute { path: "/pages/:username", to: UserPages }
page UserPages {
component: import { UserPages } from "@src/UserPages"
}
My attempt I thought this was the right way to do it but, 📄 queries.ts
// username is a parameter that comes from the URL
export const getUserPages = async ({ username }: { username: string }, context) => {
console.log(`1 username: ${username}`)

//Return all the pages with the author of `username`
return context.entities.Page.findMany({
// I don't think I am formatting the `where` correctly
where: { user: { identities: { username: username } } },
orderBy: { id: 'asc' },
})
}
// username is a parameter that comes from the URL
export const getUserPages = async ({ username }: { username: string }, context) => {
console.log(`1 username: ${username}`)

//Return all the pages with the author of `username`
return context.entities.Page.findMany({
// I don't think I am formatting the `where` correctly
where: { user: { identities: { username: username } } },
orderBy: { id: 'asc' },
})
}
I'm getting this error:
[ Server!] Unknown argument `identities`. Available options are marked with ?.
[ Server!] Unknown argument `identities`. Available options are marked with ?.
What I've tried so far - I have tried logging out the entities to try and find the right way to access the username. - I have tried talking to the AI in my IDE, but the suggestions have been to add an identity's field to the user schema. - I think wasp attaches this relation to the user entity without being explicitly defined.
7 replies