Skip to content

Conversation

@floehopper
Copy link
Contributor

This adds a new on_login_success configuration option. If this option is set to a Proc and the login was successful, the Proc will be called in the context of the RpiAuth::AuthController#callback action, i.e. current_user will be available. This is intended to allow apps to record successful logins.

I'm not convinced that using instance_exec is the most sensible approach, but I decided it was better to be consistent with the way the success_redirect option is implemented.

If the Proc raises an exception, this will be rescued and the exception will be logged as a warning in the Rails log. This is so that the login will still complete successfully, even if there was a problem recording it.

The immediate motivation for adding this is so we can record successful student logins in experience-cs in order to be able to calculate the "active users" metric described in this issue. Unfortunately while this information is available in the profile app database for regular users; it's not available for student users.

@github-actions
Copy link

github-actions bot commented Aug 14, 2025

Test coverage: 100.0%

fspeirs
fspeirs previously approved these changes Aug 14, 2025
Copy link

@fspeirs fspeirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes make sense to me.

This adds a new `on_login_success` configuration option. If this option
is set to a `Proc` and the login was successful, the `Proc` will be
called in the context of the `RpiAuth::AuthController#callback` action,
i.e. `current_user` will be available. This is intended to allow apps to
record successful logins.

I'm not convinced that using `instance_exec` is the most sensible
approach, but I decided it was better to be consistent with the way
the `success_redirect` option is implemented.

If the `Proc` raises an exception, this will be rescued and the
exception will be logged as a warning in the Rails log. This is so that
the login will still complete successfully, even if there was a problem
recording it.

The immediate motivation for adding this is so we can record successful
*student* logins in `experience-cs` in order to be able to calculate the
"active users" metric described in this issue [1]. Unfortunately while
this information is available in the `profile` app database for regular
users; it's not available for student users.

[1]: https://github.com/RaspberryPiFoundation/experience-cs/issues/727
@floehopper floehopper merged commit d8559a2 into main Aug 18, 2025
13 checks passed
@floehopper floehopper deleted the add-on-login-success-callback branch August 18, 2025 10:21
floehopper added a commit that referenced this pull request Aug 18, 2025
### Added

- Add optional `on_login_success` callback (#90)

### Fixed

- Return boolean from `AccountTypes#student_account?` (#91)
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

Successfully merging this pull request may close these issues.

4 participants