mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(server): remove default auth redirect url (#8140)
This commit is contained in:
@@ -138,8 +138,7 @@ export class AuthController {
|
|||||||
res: Response,
|
res: Response,
|
||||||
email: string,
|
email: string,
|
||||||
callbackUrl = '/magic-link',
|
callbackUrl = '/magic-link',
|
||||||
|
redirectUrl?: string
|
||||||
redirectUrl = this.url.home
|
|
||||||
) {
|
) {
|
||||||
// send email magic link
|
// send email magic link
|
||||||
const user = await this.user.findUserByEmail(email);
|
const user = await this.user.findUserByEmail(email);
|
||||||
@@ -155,7 +154,11 @@ export class AuthController {
|
|||||||
const magicLink = this.url.link(callbackUrl, {
|
const magicLink = this.url.link(callbackUrl, {
|
||||||
token,
|
token,
|
||||||
email,
|
email,
|
||||||
redirect_uri: redirectUrl,
|
...(redirectUrl
|
||||||
|
? {
|
||||||
|
redirect_uri: redirectUrl,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await this.auth.sendSignInEmail(email, magicLink, !user);
|
const result = await this.auth.sendSignInEmail(email, magicLink, !user);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
OauthAccountAlreadyConnected,
|
OauthAccountAlreadyConnected,
|
||||||
OauthStateExpired,
|
OauthStateExpired,
|
||||||
UnknownOauthProvider,
|
UnknownOauthProvider,
|
||||||
URLHelper,
|
|
||||||
} from '../../fundamentals';
|
} from '../../fundamentals';
|
||||||
import { OAuthProviderName } from './config';
|
import { OAuthProviderName } from './config';
|
||||||
import { OAuthAccount, Tokens } from './providers/def';
|
import { OAuthAccount, Tokens } from './providers/def';
|
||||||
@@ -31,7 +30,6 @@ export class OAuthController {
|
|||||||
private readonly auth: AuthService,
|
private readonly auth: AuthService,
|
||||||
private readonly oauth: OAuthService,
|
private readonly oauth: OAuthService,
|
||||||
private readonly user: UserService,
|
private readonly user: UserService,
|
||||||
private readonly url: URLHelper,
|
|
||||||
private readonly providerFactory: OAuthProviderFactory,
|
private readonly providerFactory: OAuthProviderFactory,
|
||||||
private readonly db: PrismaClient
|
private readonly db: PrismaClient
|
||||||
) {}
|
) {}
|
||||||
@@ -41,7 +39,7 @@ export class OAuthController {
|
|||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async preflight(
|
async preflight(
|
||||||
@Body('provider') unknownProviderName?: string,
|
@Body('provider') unknownProviderName?: string,
|
||||||
@Body('redirect_uri') redirectUri: string = this.url.home
|
@Body('redirect_uri') redirectUri?: string
|
||||||
) {
|
) {
|
||||||
if (!unknownProviderName) {
|
if (!unknownProviderName) {
|
||||||
throw new MissingOauthQueryParameter({ name: 'provider' });
|
throw new MissingOauthQueryParameter({ name: 'provider' });
|
||||||
|
|||||||
@@ -58,10 +58,7 @@ export const Component = () => {
|
|||||||
auth
|
auth
|
||||||
.signInMagicLink(data.email, data.token)
|
.signInMagicLink(data.email, data.token)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// compatible with old client
|
nav(data.redirectUri ?? '/');
|
||||||
if (data.redirectUri) {
|
|
||||||
nav(data.redirectUri);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
nav(`/signIn?error=${encodeURIComponent(e.message)}`);
|
nav(`/signIn?error=${encodeURIComponent(e.message)}`);
|
||||||
|
|||||||
@@ -60,9 +60,8 @@ export const Component = () => {
|
|||||||
auth
|
auth
|
||||||
.signInOauth(data.code, data.state)
|
.signInOauth(data.code, data.state)
|
||||||
.then(({ redirectUri }) => {
|
.then(({ redirectUri }) => {
|
||||||
if (redirectUri) {
|
// TODO(@forehalo): need a good way to go back to previous tab and close current one
|
||||||
nav(redirectUri);
|
nav(redirectUri ?? '/');
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
nav(`/signIn?error=${encodeURIComponent(e.message)}`);
|
nav(`/signIn?error=${encodeURIComponent(e.message)}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user