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

Reject promise in checkError with logoutUser: false and without redirectTo causes an error #10172 #10177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rktamil
Copy link

@rktamil rktamil commented Sep 1, 2024

Add null check for redirect and When redirect is not provided, I returned false and let the called handles the redirect.

This may not be ideal solution, happy to discuss as this is my my first contribution.

Fixes #10172

@djhi
Copy link
Collaborator

djhi commented Sep 2, 2024

Hi, thanks for contributing. Can you please first explain the issue?

@rktamil
Copy link
Author

rktamil commented Sep 2, 2024 via email

Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

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

Your solution seems good to me, but it would be nice if you could prove it works by adding automated tests. Can you please add one?

Comment on lines +115 to +116
// If there is not redirect return false saying loguout is not successful
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should rather return true here, since logout was explicitly not requested, and I'm afraid this will throw another error in this code:

return logoutIfAccessDenied(error).then(
loggedOut => {
if (loggedOut)
return {
data: arrayReturnTypes.includes(
type
)
? []
: {},
};
throw error;
}
);

Comment on lines 103 to +116
if (logoutUser) {
logout({}, redirectTo);
} else {
if (redirectTo.startsWith('http')) {
// absolute link (e.g. https://my.oidc.server/login)
window.location.href = redirectTo;
if (redirectTo != null) {
if (redirectTo.startsWith('http')) {
// absolute link (e.g. https://my.oidc.server/login)
window.location.href = redirectTo;
} else {
// internal location
navigate(redirectTo);
}
} else {
// internal location
navigate(redirectTo);
// If there is not redirect return false saying loguout is not successful
return false;
Copy link

@Ritzrawal Ritzrawal Dec 22, 2024

Choose a reason for hiding this comment

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

I think it would be better instead of using this nested if else condition we can make functions and use. This will help others to understand more easily and help to maintain the clean code e.g:


const handleRedirect = (url) => {
        if (url.startsWith('http')) {
            window.location.href = url; 
        } else {
            navigate(url); 
        }
    };



    if (logoutUser) {
        logout({}, redirectTo);
    } else if (redirectTo) {
        handleRedirect(redirectTo);
    } else {
    
        return false;
    }
};

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.

Reject promise in checkError with logoutUser: false and without redirectTo causes an error
4 participants