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

feat: Improved callbacks #3

Merged
merged 1 commit into from
Dec 14, 2023
Merged

Conversation

rhatherall
Copy link
Member

Callbacks are now named better and provide access to the request instead
of the session. Requests are more useful than sessions and still provide
access to the session should you need it.

The on_valid_login callback has been renamed to after_login and the
session is replaced with a request object. For example:

config.after_login = lambda do |token, user_info, request|
  user = User.where(identifier: user_info.sub).first_or_create do |user|
    user.email = user_info.email
  end
  request.session[:user_id] = user.id
end

The on_logout callback has been renamed to before_logout and the
session is replaced with a request object. For example:

config.before_logout = lambda do |request|
  # Your last chance to do something before the session is reset.
end

BREAKING CHANGE: The callback signatures have changed. Initializers must
be updated.

Callbacks are now named better and provide access to the request instead
of the session. Requests are more useful than sessions and still provide
access to the session should you need it.

The `on_valid_login` callback has been renamed to `after_login` and the
session is replaced with a request object. For example:
```ruby
config.after_login = lambda do |token, user_info, request|
  user = User.where(identifier: user_info.sub).first_or_create do |user|
    user.email = user_info.email
  end
  request.session[:user_id] = user.id
end
```

The `on_logout` callback has been renamed to `before_logout` and the
session is replaced with a request object. For example:
```ruby
config.before_logout = lambda do |request|
  # Your last chance to do something before the session is reset.
end
```

BREAKING CHANGE: The callback signatures have changed. Initializers must
be updated.
@rhatherall rhatherall self-assigned this Dec 14, 2023
@rhatherall rhatherall merged commit c94d53d into develop Dec 14, 2023
4 checks passed
@rhatherall rhatherall deleted the feature/improve-callbacks branch December 14, 2023 19:30
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.

1 participant