Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use User::PrimaryKeyType all over #791

Open
jwoertink opened this issue Feb 28, 2023 · 1 comment
Open

Use User::PrimaryKeyType all over #791

jwoertink opened this issue Feb 28, 2023 · 1 comment

Comments

@jwoertink
Copy link
Member

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.

@jwoertink
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant