luckyframework / lucky_cli

A Crystal command-line tool for generating new Lucky Web Applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use User::PrimaryKeyType all over

jwoertink opened this issue · comments

There's a few spots that use Int64 and assumes that is the User's ID type, but we can use User::PrimaryKeyType instead which will resolve as Int64 or UUID... or really whatever you're using.

Taking a look at this one doesn't seem to be as straight forward as just using that type all over. There's a few spots where we treat the id as a String, then cast it with to_i64. My first thought is we'd need some sort of cast_to_primary_key type method which could have string.to_i64, then just have 1 spot you change this and it works everywhere...

Then again... I know you can do .id("4") in Avram, and it handles it on its own.. Maybe we just allow the String version to be passed around since that works for both Ints and UUID?

If anyone else wants to look in to this, here's a few of the files that need looking at. I may have missed some

def self.decode_user_id(token : String) : Int64?
payload, _header = JWT.decode(token, Lucky::Server.settings.secret_key_base, ALGORITHM)
payload["user_id"].to_s.to_i64

html NewPage, operation: operation, user_id: user_id.to_i64

html NewPage, operation: ResetPassword.new, user_id: user_id.to_i64