W
Wasp3mo ago
Sven

how do I show the users email on my frontend.

Hi kapa how can i show the users email on my frontend. Also for my opensaas project how can i extend the register field to have more things related to b2b.
7 Replies
kapa.ai
kapa.ai3mo ago
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To display the user's email on your frontend, you can use the getEmail helper function provided by Wasp. This function returns the user's email or null if the user doesn't have an email auth identity. Here's an example of how you can use it:
import { getEmail } from 'wasp/auth'

const MainPage = ({ user }) => {
const email = getEmail(user)
// Now you can use the email variable in your JSX
// ...
}
import { getEmail } from 'wasp/auth'

const MainPage = ({ user }) => {
const email = getEmail(user)
// Now you can use the email variable in your JSX
// ...
}
You can find more details about this in the Wasp documentation (https://wasp-lang.dev/docs/auth/entities#accessing-the-auth-fields). As for extending the registration field for your OpenSaaS project, you can customize the SignupForm component by passing in the additionalFields prop. This prop can be either a list of extra fields or a render function. Here's an example:
import {
SignupForm,
FormError,
FormInput,
FormItemGroup,
FormLabel,
} from 'wasp/client/auth'

export const SignupPage = () => {
return (
<SignupForm
additionalFields={[
{
name: 'address',
label: 'Address',
type: 'input',
validations: {
required: 'Address is required',
},
},
// Add more fields as needed
]}
/>
)
}
import {
SignupForm,
FormError,
FormInput,
FormItemGroup,
FormLabel,
} from 'wasp/client/auth'

export const SignupPage = () => {
return (
<SignupForm
additionalFields={[
{
name: 'address',
label: 'Address',
type: 'input',
validations: {
required: 'Address is required',
},
},
// Add more fields as needed
]}
/>
)
}
You can find more details about this in the Wasp documentation (https://wasp-lang.dev/docs/auth/overview#signupform-customization). Remember, for the server to know how to save these extra fields to the database, you need to define the auth.methods.{authMethod}.userSignupFields field in your main.wasp file. Here's an example:
app crudTesting {
// ...
auth: {
userEntity: User,
methods: {
usernameAndPassword: {
userSignupFields: import { userSignupFields } from "@src/auth/signup",
},
},
onAuthFailedRedirectTo: "/login",
},
}
app crudTesting {
// ...
auth: {
userEntity: User,
methods: {
usernameAndPassword: {
userSignupFields: import { userSignupFields } from "@src/auth/signup",
},
},
onAuthFailedRedirectTo: "/login",
},
}
You can find more details about this in the Wasp documentation (https://wasp-lang.dev/docs/auth/overview#signup-fields-customization). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Sven
SvenOP3mo ago
doesnt work, i cant seem to get the username/email on a page. Do i really need to write my own query for that?
NEROX
NEROX3mo ago
If you are using the SaaS template you can check @src/user/AccountPage.tsx
Sven
SvenOP3mo ago
xxxx.tsx:131 Uncaught TypeError: Cannot read properties of undefined (reading 'email') would this be because it is not loaded yet or something when adding {!!user.email && ( )} it still does not work i imported : import type { User } from 'wasp/entities'; and added : ({ user }: { user: User })
NEROX
NEROX3mo ago
You can trigger Kapa mentioning it again and give him more code context
NEROX
NEROX3mo ago
I just created this
No description
No description
Sven
SvenOP3mo ago
Ill try that Weird that in accountpahe it works But when i do it somewhere else it doesnt Probably some load await
Want results from more Discord servers?
Add your server