Skip to content

Commit 4665a6f

Browse files
authored
veb.auth: update the README.md example (#25245)
1 parent 21c46f4 commit 4665a6f

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

vlib/veb/auth/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ pub fn (mut app App) register_user(mut ctx Context, name string, password string
5151
password_hash: auth.hash_password_with_salt(password, salt)
5252
salt: salt
5353
}
54-
sql app.db {
54+
user_id := sql app.db {
5555
insert new_user into User
56-
} or {}
57-
58-
// Get new user ID (until RETURNING is supported by ORM)
59-
if x := app.find_user_by_name(name) {
60-
// Generate and insert the token using user ID
61-
token := app.auth.add_token(x.id) or { '' }
62-
// Authenticate the user by adding the token to the cookies
63-
ctx.set_cookie(name: 'token', value: token)
64-
}
56+
} or { 0 }
57+
58+
// Generate and insert the token using user ID
59+
token := app.auth.add_token(user_id) or { '' }
60+
// Authenticate the user by adding the token to the cookies
61+
ctx.set_cookie(name: 'token', value: token)
6562
6663
return ctx.redirect('/')
6764
}
@@ -97,4 +94,4 @@ iteration. This is not secure for production use, and you should use a more secu
9794
algorithm and multiple iterations.
9895

9996
See also:
100-
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)
97+
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)

0 commit comments

Comments
 (0)