Redirect user back to the first landing page after external login (#1742)

* Preserve fallbackuri on external login

* Change default uri to "/"
This commit is contained in:
Wojciech Mista 2022-01-24 10:23:19 +01:00 committed by GitHub
parent 03f6034531
commit ede2094d30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,6 +42,11 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
setRequestedExternalPluginId setRequestedExternalPluginId
] = useLocalStorage("requestedExternalPluginId", null); ] = useLocalStorage("requestedExternalPluginId", null);
const [fallbackUri, setFallbackUri] = useLocalStorage(
"externalLoginFallbackUri",
null
);
const handleSubmit = async (data: LoginFormData) => { const handleSubmit = async (data: LoginFormData) => {
const result = await login(data.email, data.password); const result = await login(data.email, data.password);
const errors = result?.errors || []; const errors = result?.errors || [];
@ -50,6 +55,8 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
}; };
const handleRequestExternalAuthentication = async (pluginId: string) => { const handleRequestExternalAuthentication = async (pluginId: string) => {
setFallbackUri(location.pathname);
const result = await requestLoginByExternalPlugin(pluginId, { const result = await requestLoginByExternalPlugin(pluginId, {
redirectUri: urlJoin( redirectUri: urlJoin(
window.location.origin, window.location.origin,
@ -70,7 +77,8 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
state state
}); });
if (result && !result?.errors?.length) { if (result && !result?.errors?.length) {
navigate(APP_DEFAULT_URI); navigate(fallbackUri ?? "/");
setFallbackUri(null);
} }
}; };