soofstad / react-oauth2-pkce

Provider agnostic OAuth2 Authorization Code flow with PKCE for React
MIT License
125 stars 53 forks source link

💡 [REQUEST] - Enhance Logout Functionality #156

Closed kleysonfiretail closed 5 months ago

kleysonfiretail commented 6 months ago

Summary

The react-oauth2-code-pkce library currently lacks some functionalities that are common in similar libraries like auth0-react, which affects developers transitioning between these libraries. To bridge this gap, I propose the following enhancements:

Basic Example

Here are some basic examples of how these features could be implemented:

PostLogout Callback Example:

const authConfig: TAuthConfig = {
 // ... //
  postLogout: () => {
    console.log("Logout completed!");
    // Additional cleanup actions can be performed here
  }
};

Additional Parameters for logOut() Example:

const additionalParameters = {
  returnTo: '/home',
  customParam: 'value'
};
logOut(additionalParameters);

LogoutInProgress State Example:

const { logoutInProgress } = useAuth();

if (logoutInProgress) {
  return <div>Logging out...</div>;
}

Drawbacks

Complexity: Introducing these features could increase the complexity of the library's API, potentially making it harder to maintain and understand.

Scope Creep: Each new feature could lead to requests for more similar features, potentially diverting focus from the core functionality of the library.

Performance: Adding more features, especially state management like logoutInProgress, might impact the performance if not implemented efficiently.

soofstad commented 6 months ago

Hi @kleysonfiretail Thank you for the suggestions. I think these are reasonable requests. Params to the login() is something I have though of doing for some time, just never heard anyone actually missing it. PostLogoutCallback is also a nice feature. Easy enough to add, and fits well with the existing callbacks pattern.

Not sure how you would use "LogoutInProgress", as it is a synchronous function, with no state and redirect back and fourth involved. If you could give an example for when you would need this to help me understand, that would be great :slightly_smiling_face:

soofstad commented 5 months ago

Closing this in favor of the other 2 issues