therewillbecode / poker-maison

🂺 A Multiplayer Poker App Crafted with Haskell and React
309 stars 34 forks source link

Do not /login #12

Closed IvanKonevJr closed 4 years ago

IvanKonevJr commented 4 years ago

Status: 401 Unauthorized 0.020413627s

In everything wrote this, /register is working, but already wrote that

why on token generation write: Left KeySizeTooSmall ???

therewillbecode commented 4 years ago

You need to add more characters to the key used to signing auth tokens.

This key is obtained from an environment variable called "secret" by the app.

secret=mysecretkey stack run

IvanKonevJr commented 4 years ago

oh thank you very much

therewillbecode commented 4 years ago

No problem just let me know if you have any other issues and I will help.

IvanKonevJr commented 4 years ago

after registration: image

IvanKonevJr commented 4 years ago

now registration not working

therewillbecode commented 4 years ago

Are you trying to reregister an account which already exists?

Try logging in.

IvanKonevJr commented 4 years ago

no no, registration not working, new user do not added

IvanKonevJr commented 4 years ago

why login only from localhost, i try connect to my localhost from ngrok - and request not sended ??? can you try connect throw ngrok?

therewillbecode commented 4 years ago

So when you register you get a 401 and the user isn't inserted into the DB?

IvanKonevJr commented 4 years ago

So when you register you get a 401 and the user isn't inserted into the DB?

Yes it is

IvanKonevJr commented 4 years ago

and how to add bots to game?

IvanKonevJr commented 4 years ago

So when you register you get a 401 and the user isn't inserted into the DB?

Yes it is

i found and fix problem with registration

therewillbecode commented 4 years ago

So what was causing the problem?

IvanKonevJr commented 4 years ago

a problem is a not correct setting urls in profile... and how to add bots to game? and redis do not used?

Mijobar commented 4 years ago

Also having the same issue... Why I click register is doesn't do anything my guess is it's not saving to redis server?

michael@michael-HP-Pro3500-Series:~/Desktop/ten-poker-master/server$ stack run "couldn't parse redishost from env default used" "REDIS config: " ConnInfo {connectHost = "localhost", connectPort = PortNumber 6379, connectAuth = Nothing, connectDatabase = 0, connectMaxConnections = 50, connectMaxIdleTime = 30s, connectTimeout = Nothing, connectTLSParams = Nothing}

IvanKonevJr commented 4 years ago

yes this is is write in log

Mijobar commented 4 years ago

@LaoTsing is the default redis ConnInfo good? If no, can you give me an example and where i need to put it? Thanks!

therewillbecode commented 4 years ago

@Mijobar The default redis ConnInfo is good if you are running redis on localhost on port 6379.

These are the default settings redis uses when you run redis-server.

If you for some reason need to change the defaults the app uses then you would start by looking here as this where the default configuration is set.

IvanKonevJr commented 4 years ago

@therewillbecode why redis not used automatically?

IvanKonevJr commented 4 years ago

@LaoTsing is the default redis ConnInfo good? If no, can you give me an example and where i need to put it? Thanks!

if you used redis say me how)

DavidRSeWell commented 4 years ago

@therewillbecode Really awesome project! I am having a similar issue it seems. I am not too familiar with the redis / postgres workflow so it is probably something small. Similar to Lao when I create a user I get a 401 but the user gets created I can see in the postgres db. I also get a 401 when trying to login with that user I just created. This the key I am using secret="tenpokersupersecretkey123" I am not sure how to debug this. Any suggestions? It seems like maybe it didnt like the password I provided because the password I used to register is ignored and a random one is set in the db. Unless it is just storing the password safely.

elv1n commented 4 years ago

So what was causing the problem?

I have got the same problem, the user saves into DB but then cannot authorize it. Redis is on 6379 and responding for 'redis-cli ping'

❯ stack run
"Redis host name from env is: "
"127.0.0.1"
"REDIS config: "
ConnInfo {connectHost = "127.0.0.1", connectPort = PortNumber 6379, connectAuth = Nothing, connectDatabase = 0, connectMaxConnections = 50, connectMaxIdleTime = 30s, connectTimeout = Nothing, connectTLSParams = Nothing}
[Debug#SQL] SELECT "id", "name" FROM "tables" WHERE ("name"=?) LIMIT 1; [PersistText "Black"]
[Debug#SQL] SELECT "id", "name" FROM "tables" WHERE ("name"=?) LIMIT 1; [PersistText "Black"]
[Debug#SQL] UPDATE "users" SET "available_chips"=? WHERE ("available_chips"<?); [PersistInt64 200000,PersistInt64 200000]
"Socket server listening on 5000"
OPTIONS /register
  Accept: */*
  Status: 200 OK 0.000024s
[Debug#SQL] SELECT "id", "username", "email", "password", "available_chips", "chips_in_play", "created_at" FROM "users" WHERE ("email"=?) LIMIT 1; [PersistText "test@testcom"]
[Debug#SQL] SELECT "id", "username", "email", "password", "available_chips", "chips_in_play", "created_at" FROM "users" WHERE ("username"=?) LIMIT 1; [PersistText "elvin3"]
[Debug#SQL] INSERT INTO "users"("username","email","password","available_chips","chips_in_play","created_at") VALUES(?,?,?,?,?,?) RETURNING "id"; [PersistText "test",PersistText "test@elvintestcom",PersistText "\154\180\210\STXAr\200FoXB\241l\"\185EbfAkq\ETX\DC1\189\140Z\148\199\159#1\187",PersistInt64 3000,PersistInt64 0,PersistUTCTime 2020-04-15 19:02:51.917578 UTC]
POST /register
  Request Body: {"newUsername":"test","newUserEmail":"test@test.com","newUserPassword":"test"}
  Accept: application/json, text/plain, */*
  Status: 401 Unauthorized 0.020263s
[Debug#SQL] UPDATE "users" SET "available_chips"=? WHERE ("available_chips"<?); [PersistInt64 200000,PersistInt64 200000]
therewillbecode commented 4 years ago

Also having the same issue... Why I click register is doesn't do anything my guess is it's not saving to redis server?

michael@michael-HP-Pro3500-Series:~/Desktop/ten-poker-master/server$ stack run "couldn't parse redishost from env default used" "REDIS config: " ConnInfo {connectHost = "localhost", connectPort = PortNumber 6379, connectAuth = Nothing, connectDatabase = 0, connectMaxConnections = 50, connectMaxIdleTime = 30s, connectTimeout = Nothing, connectTLSParams = Nothing}

This is not an issue. All it says is - you didn't pass in envinornment variables to override the Redis settings so we are going to use the defaults.

therewillbecode commented 4 years ago

@elv1n @LaoTsing @befeltingu @Mijobar

So the issue is that the secret key you are supplying as an environment variable to your server is not 32 characters long.

I have updated the example secret in the Readme to be the correct length.

I also updated the code so that you will see a "KeySizeTooSmall" error if the server is given too short a secret. Then this invalid secret is then used to sign a JWT when user registers. Of course this doesn't work and you get a 401.

Does using a 32 character long key for the secret fix your 401 issue?

DavidRSeWell commented 4 years ago

@therewillbecode That seemed to do it for me. Thanks!