this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add support for the authsuccess message

+29 -12
+29 -12
client/src/lumina_client.gleam
··· 358 358 } 359 359 } 360 360 Ok(f) -> { 361 - console.error("Unhandled message: " <> string.inspect(f)) 361 + let message_variant = 362 + json.parse(notice, ws_msg_typedefiner()) 363 + |> result.unwrap("Unparsable message") 364 + console.error( 365 + "Unhandled message: " 366 + <> message_variant 367 + <> " => " 368 + <> string.inspect(f), 369 + ) 362 370 #(model_, effect.none()) 363 371 } 364 372 Error(err) -> { 365 373 console.error( 366 374 "Message could not be parsed:" 367 - <> premixed.text_error_red(string.inspect(err)), 375 + // <> premixed.text_error_red(string.inspect(err)), 376 + <> premixed.text_error_red(notice), 368 377 ) 369 378 #(model_, effect.none()) 370 379 } 371 380 } 372 381 lustre_websocket.OnBinaryMessage(msg) -> { 373 - msg 382 + console.warn( 383 + "Received unexpected:" <> premixed.text_cyan(string.inspect(msg)), 384 + ) 374 385 // Ignore this. We don't expect binary messages, as we cannot tag them with how the decoder works right now. We only expect text messages, with base64-encoded bitarrays in their fields if so needed. 375 386 // So, continue with the model as is: 376 387 #(model_, effect.none()) 377 388 } 378 389 lustre_websocket.OnClose(reason) -> { 379 - reason 390 + console.warn( 391 + "Given close reason:" <> premixed.text_cyan(string.inspect(reason)), 392 + ) 380 393 #(Model(..model_, ws: Some(None)), effect.none()) 381 394 } 382 395 lustre_websocket.OnOpen(socket) -> #( ··· 409 422 RegisterPrecheck( 410 423 email: String, 411 424 username: String, 412 - // Password only once? Yes, the equal password check is done in the view. 425 + // Password only once? Yes, the equal password check is done in the view/update themselves. 413 426 password: String, 414 427 ) 415 428 RegisterPrecheckResponse(ok: Bool, why: String) 416 429 RegisterRequest(email: String, username: String, password: String) 417 430 LoginAuthenticationRequest(email_username: String, password: String) 431 + AuthenticationSuccess(username: String, token: String) 418 432 Undecodable 419 433 } 420 434 ··· 440 454 #("username", json.string(username)), 441 455 #("password", json.string(password)), 442 456 ]) 443 - RegisterPrecheckResponse(ok, why) -> 444 - json.object([ 445 - #("type", json.string("register_precheck_response")), 446 - #("ok", json.bool(ok)), 447 - #("why", json.string(why)), 448 - ]) 449 - Greeting(_) | Undecodable -> 457 + // And the client should never have to encode the next few: 458 + Greeting(_) 459 + | Undecodable 460 + | RegisterPrecheckResponse(_, _) 461 + | AuthenticationSuccess(_, _) -> 450 462 json.object([#("type", json.string("unknown"))]) 451 463 } 452 464 } 453 465 454 466 fn ws_msg_decoder(variant: String) -> decode.Decoder(WsMsg) { 455 467 case variant { 468 + "auth_success" -> { 469 + use username <- decode.field("username", decode.string) 470 + use token <- decode.field("token", decode.string) 471 + decode.success(AuthenticationSuccess(username:, token:)) 472 + } 456 473 "unknown" -> decode.success(Undecodable) 457 474 "login_authentication_request" -> { 458 475 use email_username <- decode.field("email_username", decode.string)