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

This commit is contained in:
forehalo
2024-09-06 06:26:59 +00:00
parent a027cef457
commit 64d2b926a2
4 changed files with 10 additions and 13 deletions

View File

@@ -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);

View File

@@ -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' });

View File

@@ -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)}`);

View File

@@ -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)}`);