Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(server): remove default auth redirect url (#8140)

forehalo64d2b926a22b
diff --git a/packages/backend/server/src/core/auth/controller.ts b/packages/backend/server/src/core/auth/controller.ts
index 6aaef286ee..7db022278b 100644
--- a/packages/backend/server/src/core/auth/controller.ts
+++ b/packages/backend/server/src/core/auth/controller.ts
@@ -138,8 +138,7 @@ export class AuthController {
res: Response,
email: string,
callbackUrl = '/magic-link',
-
- redirectUrl = this.url.home
+ redirectUrl?: string
) {
// send email magic link
const user = await this.user.findUserByEmail(email);
@@ -155,7 +154,11 @@ export class AuthController {
const magicLink = this.url.link(callbackUrl, {
token,
email,
- redirect_uri: redirectUrl,
+ ...(redirectUrl
+ ? {
+ redirect_uri: redirectUrl,
+ }
+ : {}),
});
const result = await this.auth.sendSignInEmail(email, magicLink, !user);
diff --git a/packages/backend/server/src/plugins/oauth/controller.ts b/packages/backend/server/src/plugins/oauth/controller.ts
index 0b69fe3c9e..999c34ef3d 100644
--- a/packages/backend/server/src/plugins/oauth/controller.ts
+++ b/packages/backend/server/src/plugins/oauth/controller.ts
@@ -18,7 +18,6 @@ import {
OauthAccountAlreadyConnected,
OauthStateExpired,
UnknownOauthProvider,
- URLHelper,
} from '../../fundamentals';
import { OAuthProviderName } from './config';
import { OAuthAccount, Tokens } from './providers/def';
@@ -31,7 +30,6 @@ export class OAuthController {
private readonly auth: AuthService,
private readonly oauth: OAuthService,
private readonly user: UserService,
- private readonly url: URLHelper,
private readonly providerFactory: OAuthProviderFactory,
private readonly db: PrismaClient
) {}
@@ -41,7 +39,7 @@ export class OAuthController {
@HttpCode(HttpStatus.OK)
async preflight(
@Body('provider') unknownProviderName?: string,
- @Body('redirect_uri') redirectUri: string = this.url.home
+ @Body('redirect_uri') redirectUri?: string
) {
if (!unknownProviderName) {
throw new MissingOauthQueryParameter({ name: 'provider' });
diff --git a/packages/frontend/core/src/pages/auth/magic-link.tsx b/packages/frontend/core/src/pages/auth/magic-link.tsx
index 6cfaf4b81a..ede536e573 100644
--- a/packages/frontend/core/src/pages/auth/magic-link.tsx
+++ b/packages/frontend/core/src/pages/auth/magic-link.tsx
@@ -58,10 +58,7 @@ export const Component = () => {
auth
.signInMagicLink(data.email, data.token)
.then(() => {
- // compatible with old client
- if (data.redirectUri) {
- nav(data.redirectUri);
- }
+ nav(data.redirectUri ?? '/');
})
.catch(e => {
nav(`/signIn?error=${encodeURIComponent(e.message)}`);
diff --git a/packages/frontend/core/src/pages/auth/oauth-callback.tsx b/packages/frontend/core/src/pages/auth/oauth-callback.tsx
index b62f72bddb..12349822fd 100644
--- a/packages/frontend/core/src/pages/auth/oauth-callback.tsx
+++ b/packages/frontend/core/src/pages/auth/oauth-callback.tsx
@@ -60,9 +60,8 @@ export const Component = () => {
auth
.signInOauth(data.code, data.state)
.then(({ redirectUri }) => {
- if (redirectUri) {
- nav(redirectUri);
- }
+ // TODO(@forehalo): need a good way to go back to previous tab and close current one
+ nav(redirectUri ?? '/');
})
.catch(e => {
nav(`/signIn?error=${encodeURIComponent(e.message)}`);