fix(core): redirect to old page after login via 404 page (#8588)

fix AF-1487

When visit a cloud worskapce page without login, we should allow the user to redirect back to that page after login.

The logic is only added for this case, including login with email magin link + google login. Login with password is already working without changes.
This commit is contained in:
pengx17
2024-10-25 03:43:00 +00:00
parent 08319bc560
commit 8f694aceb7
13 changed files with 135 additions and 35 deletions
@@ -112,17 +112,26 @@ export class AuthService extends Service {
async sendEmailMagicLink(
email: string,
verifyToken: string,
challenge?: string
challenge?: string,
redirectUrl?: string // url to redirect to after signed-in
) {
track.$.$.auth.signIn({ method: 'magic-link' });
try {
const magicLinkUrlParams = new URLSearchParams();
if (redirectUrl) {
magicLinkUrlParams.set('redirect_uri', redirectUrl);
}
magicLinkUrlParams.set(
'client',
BUILD_CONFIG.isElectron && appInfo ? appInfo.schema : 'web'
);
await this.fetchService.fetch('/api/auth/sign-in', {
method: 'POST',
body: JSON.stringify({
email,
// we call it [callbackUrl] instead of [redirect_uri]
// to make it clear the url is used to finish the sign-in process instead of redirect after signed-in
callbackUrl: `/magic-link?client=${BUILD_CONFIG.isElectron ? appInfo?.schema : 'web'}`,
callbackUrl: `/magic-link?${magicLinkUrlParams.toString()}`,
}),
headers: {
'content-type': 'application/json',