From 4665a6f4a8e1648609b9df7d56430e52c8c45adb Mon Sep 17 00:00:00 2001 From: 449 <449@users.noreply.github.com> Date: Sat, 6 Sep 2025 05:22:30 +0100 Subject: [PATCH] veb.auth: update the README.md example (#25245) --- vlib/veb/auth/README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/vlib/veb/auth/README.md b/vlib/veb/auth/README.md index 20c2f36eb9..f1215b3070 100644 --- a/vlib/veb/auth/README.md +++ b/vlib/veb/auth/README.md @@ -51,17 +51,14 @@ pub fn (mut app App) register_user(mut ctx Context, name string, password string password_hash: auth.hash_password_with_salt(password, salt) salt: salt } - sql app.db { + user_id := sql app.db { insert new_user into User - } or {} + } or { 0 } - // Get new user ID (until RETURNING is supported by ORM) - if x := app.find_user_by_name(name) { - // Generate and insert the token using user ID - token := app.auth.add_token(x.id) or { '' } - // Authenticate the user by adding the token to the cookies - ctx.set_cookie(name: 'token', value: token) - } + // Generate and insert the token using user ID + token := app.auth.add_token(user_id) or { '' } + // Authenticate the user by adding the token to the cookies + ctx.set_cookie(name: 'token', value: token) return ctx.redirect('/') } @@ -97,4 +94,4 @@ iteration. This is not secure for production use, and you should use a more secu algorithm and multiple iterations. See also: -- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) \ No newline at end of file +- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)