Genie Discord forum

Author Avatardusty.irwin
10/6/2023, 12:36:57 AM

Hi all, I've recently updated my Genie project to v5 and found that the current_user() function does not seem to work. I'm using this code for a user to login in my AuthenicationController module:

function login()
  try
    user = findone(User, username=params(:username), password=Users.hash_password(params(:password)))
    authenticate(user.id, GenieSession.session(params()))

    redirect("/tools") 

  catch ex
    @error ex
    flash("Authentication failed! ")
    redirect(:show_login)
  end
end

...which works. However, once the user selects a 'tool' (an app), the app needs to retreive the user's name from the db. Previously, I did this by calling current_user().name, however, now that is returning a Nothing object and crashes the app.

What is the standard method for retrieving the name (or username) of a logged in user in Genie v5?

Author Avataressenciary
10/6/2023, 3:22:43 PM

@dusty.irwin it depends on what exactly you did as part of your Genie 5 upgrade. Coming from v4 it's a major and breaking release. You can find the migration guide here - please apply the changes the make sense to your app: https://genieframework.com/docs/genie/v5.11/docs/guides/Migrating-from-v4-to-v5.html#Upgrade-from-v4-to-v5

Author Avataressenciary
10/6/2023, 3:23:18 PM

the Auth plugin and the current_user should function the same in Genie 5 - so most likely it's Genie itself that's causing issues due to an incomplete upgrade