W
Wasp-langβ€’2y ago
Kajatin

Cannot log in

I followed the tutorial to set up authentication. The registration works, I can see the user in the database with the hashed password. I'm using username + password authentication. On the login page I'd enter the username and password but when I click login I'm not redirected to my landing page.
app MyProject {
wasp: {
version: "^0.10.2"
},
title: "Title",
auth: {
userEntity: Player,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login"
},
client: {
rootComponent: import App from "@client/App",
},
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
authRequired: true,
component: import Main from "@client/MainPage"
}

route SignupRoute { path: "/signup", to: SignupPage }
page SignupPage {
component: import Signup from "@client/auth/SignupPage"
}

route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import Login from "@client/auth/LoginPage"
}

entity Player {=psl
id Int @id @default(autoincrement())
username String @unique
password String
psl=}
app MyProject {
wasp: {
version: "^0.10.2"
},
title: "Title",
auth: {
userEntity: Player,
methods: {
usernameAndPassword: {}
},
onAuthFailedRedirectTo: "/login"
},
client: {
rootComponent: import App from "@client/App",
},
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
authRequired: true,
component: import Main from "@client/MainPage"
}

route SignupRoute { path: "/signup", to: SignupPage }
page SignupPage {
component: import Signup from "@client/auth/SignupPage"
}

route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import Login from "@client/auth/LoginPage"
}

entity Player {=psl
id Int @id @default(autoincrement())
username String @unique
password String
psl=}
I get a 200 from http://localhost:3001/auth/local/login and my JWT token is there, but then I get a 401 from http://localhost:3001/auth/me :sadboi:
8 Replies
Kajatin
Kajatinβ€’2y ago
Update: I'm looking at the auto-generated createAuthRequiredPage component, and while the login return isSuccess=true somehow my user=null 😦 Update: Ok, turns out the auth cannot handle if my user type is not named User. I'm building a game so I wanted to call my users Player .
miho
mihoβ€’2y ago
How did your wasp file look like when you used Player? You can configure the auth entity to be any entity πŸ™‚
Kajatin
Kajatinβ€’2y ago
My wasp file was like it's shown in my original post. I've defined userEntity: Player but perhaps I was missing some other configuration?
MEE6
MEE6β€’2y ago
Wohooo @Kajatin, you just became a Waspeteer level 1!
matijash
matijashβ€’2y ago
hmm you can also explicitly define where user is sent upon successful auth, but by default it goes to "/" : https://wasp-lang.dev/docs/language/features#onauthsucceededredirectto-string-optional
matijash
matijashβ€’2y ago
is your repo public, can you share it with us?
Kajatin
Kajatinβ€’2y ago
It's public and I see you've already found it. It's not a problem that I had to call it User if you think it might be a bug I can create a minimal example after the hackathon is over and come back to you. Right now I'm just focused on the project for the hackathon 😊
martinsos
martinsosβ€’2y ago
Want results from more Discord servers?
Add your server