abehod
abehod
WWasp-lang
Created by abehod on 8/2/2024 in #đŸ™‹questions
How to access user's fields on FE from child table
I have User and BusinessDetails tables in my app and they have a one to one relationship:
entity User {=psl
id Int @id @default(autoincrement())

businessDetails BusinessDetails?
psl=}

entity BusinessDetails {=psl
id Int @id @default(autoincrement())

business User @relation(fields: [businessId], references: [id])
businessId Int @unique

subscriptionStatus String?
psl=}
entity User {=psl
id Int @id @default(autoincrement())

businessDetails BusinessDetails?
psl=}

entity BusinessDetails {=psl
id Int @id @default(autoincrement())

business User @relation(fields: [businessId], references: [id])
businessId Int @unique

subscriptionStatus String?
psl=}
On frontend we access only user's entity fields and no fields from tables which have dependencies on user table, is there a way to see subscriptionStatus on frontend with following db structure?
13 replies
WWasp-lang
Created by abehod on 6/30/2024 in #đŸ™‹questions
How to overwrite system api endpoint?
Hello, I wanna use create custom auth/me endpoint handler, which would handle this request somehow differently, I have added this api to my main.wasp file, but when I make request to auth/me old handler is used. Is there a way to kind of overwrite system api endpoints? My api in main.wasp:
api authMe {
fn: import { authMe } from "@src/server/auth/authMe.js",
entities: [User],
httpRoute: (GET, "/auth/me")
}
api authMe {
fn: import { authMe } from "@src/server/auth/authMe.js",
entities: [User],
httpRoute: (GET, "/auth/me")
}
My example authMe file:
import { serialize as superjsonSerialize } from 'superjson'
import { handleRejection } from 'wasp/server/utils'
import { throwInvalidCredentialsError } from 'wasp/auth/utils'

export const authMe = handleRejection(async (req, res) => {
console.log("Custom authMe route");
if (req.user) {
return res.json(superjsonSerialize(req.user))
} else {
throwInvalidCredentialsError()
}
})
import { serialize as superjsonSerialize } from 'superjson'
import { handleRejection } from 'wasp/server/utils'
import { throwInvalidCredentialsError } from 'wasp/auth/utils'

export const authMe = handleRejection(async (req, res) => {
console.log("Custom authMe route");
if (req.user) {
return res.json(superjsonSerialize(req.user))
} else {
throwInvalidCredentialsError()
}
})
9 replies
WWasp-lang
Created by abehod on 6/16/2024 in #đŸ™‹questions
How to add signup validation on backend
I have added new validation fields and rewrite the frontend version of signup proccess and now I am trying to add validation on backend in defineUserSignupFields but it does not work, how can I achieve validation on backend? Maybe there is a way overwrite just ensureValidArgs function?

function ensureValidArgs(args: unknown): void {
ensureValidEmail(args);
ensurePasswordIsPresent(args);
ensureValidPassword(args);
}

function ensureValidArgs(args: unknown): void {
ensureValidEmail(args);
ensurePasswordIsPresent(args);
ensureValidPassword(args);
}
9 replies
WWasp-lang
Created by abehod on 6/9/2024 in #đŸ™‹questions
How to change the order of fields in in signup page
Hello, I have added additional fields to signup form but all additional fields appear under the password and email fields, which I do not like and would like to change it:
<SignupForm
additionalFields={[
{
name: 'name',
label: 'Name',
type: 'input',
validations: {

required: 'Name is required',
},
},
{
name: 'companyName',
label: 'Company Name',
type: 'input',
validations: {
required: 'Company Name is required',
},
},
]}
/>
<SignupForm
additionalFields={[
{
name: 'name',
label: 'Name',
type: 'input',
validations: {

required: 'Name is required',
},
},
{
name: 'companyName',
label: 'Company Name',
type: 'input',
validations: {
required: 'Company Name is required',
},
},
]}
/>
How can I do so the order o my fields would be: 1) name 2) email 3) company name 4) password Thank you in advance!
5 replies