Skip to content

Commit

Permalink
fix(desktop):fix email binding (#5186)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou authored Nov 4, 2024
1 parent e6a2f8b commit 1c0f91d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions frontend/desktop/src/pages/api/auth/email/bind/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ErrorHandler } from '@/services/backend/middleware/error';
import { bindEmailGuard } from '@/services/backend/middleware/oauth';
import { filterEmailVerifyParams, verifyEmailCodeGuard } from '@/services/backend/middleware/sms';
import { bindEmailSvc } from '@/services/backend/svc/bindProvider';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';

export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
sendNewEmailCodeGuard
} from '@/services/backend/middleware/sms';
import { sendEmailCodeSvc } from '@/services/backend/svc/sms';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';
export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(req, res, ({ userUid }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { ErrorHandler } from '@/services/backend/middleware/error';
import { unbindEmailGuard } from '@/services/backend/middleware/oauth';
import { filterEmailParams, sendEmailCodeGuard } from '@/services/backend/middleware/sms';
import { sendEmailCodeSvc } from '@/services/backend/svc/sms';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';
export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(req, res, ({ userUid }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
verifyEmailCodeGuard
} from '@/services/backend/middleware/sms';
import { changeEmailBindingSvc } from '@/services/backend/svc/bindProvider';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';

export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(req, res, ({ userUid }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ErrorHandler } from '@/services/backend/middleware/error';
import { unbindEmailGuard } from '@/services/backend/middleware/oauth';
import { filterEmailVerifyParams, verifyEmailCodeGuard } from '@/services/backend/middleware/sms';
import { jsonRes } from '@/services/backend/response';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';

export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(
Expand Down
4 changes: 2 additions & 2 deletions frontend/desktop/src/pages/api/auth/email/unbind/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ErrorHandler } from '@/services/backend/middleware/error';
import { unbindEmailGuard } from '@/services/backend/middleware/oauth';
import { filterCf, filterEmailParams, sendEmailCodeGuard } from '@/services/backend/middleware/sms';
import { sendEmailCodeSvc } from '@/services/backend/svc/sms';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';

export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(req, res, ({ userUid }) =>
Expand Down
4 changes: 2 additions & 2 deletions frontend/desktop/src/pages/api/auth/email/unbind/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { filterAccessToken } from '@/services/backend/middleware/access';
import { ErrorHandler } from '@/services/backend/middleware/error';
import { filterEmailVerifyParams, verifyEmailCodeGuard } from '@/services/backend/middleware/sms';
import { unbindEmailSvc } from '@/services/backend/svc/bindProvider';
import { enablePhoneSms } from '@/services/enable';
import { enableEmailSms } from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';

export default ErrorHandler(async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!enablePhoneSms()) {
if (!enableEmailSms()) {
throw new Error('SMS is not enabled');
}
await filterAccessToken(req, res, ({ userUid }) =>
Expand Down
5 changes: 4 additions & 1 deletion frontend/desktop/src/pages/api/auth/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
enableGithub,
enableGoogle,
enablePassword,
enablePhoneSms
enablePhoneSms,
enableWechat
} from '@/services/enable';
import { NextApiRequest, NextApiResponse } from 'next';
import { ProviderType } from 'prisma/global/generated/client';
Expand Down Expand Up @@ -89,6 +90,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return enableEmailSms();
} else if (o.providerType === ProviderType.PASSWORD) {
return enablePassword();
} else if (o.providerType === ProviderType.WECHAT) {
return enableWechat();
}
return true;
})
Expand Down
6 changes: 4 additions & 2 deletions frontend/desktop/src/services/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ export const enableEnterpriseRealNameAuth = () =>
global.AppConfig.common.enterpriseRealNameAuthEnabled || false;
export const enablePassword = () => global.AppConfig.desktop.auth.idp.password?.enabled || false;
export const enableGithub = () => global.AppConfig.desktop.auth.idp.github?.enabled || false;
export const enablePhoneSms = () => global.AppConfig.desktop.auth.idp.sms?.ali?.enabled || false;
export const enableSms = () => global.AppConfig.desktop.auth.idp.sms?.enabled || false;
export const enableEmailSms = () => global.AppConfig.desktop.auth.idp.sms?.email?.enabled || false;
export const enablePhoneSms = () =>
enableSms() && !!global.AppConfig.desktop.auth.idp.sms?.ali?.enabled;
export const enableEmailSms = () =>
enableSms() && !!global.AppConfig.desktop.auth.idp.sms?.email?.enabled;
export const enableWechat = () => global.AppConfig.desktop.auth.idp.wechat?.enabled || false;
export const enableGoogle = () => global.AppConfig.desktop.auth.idp.google?.enabled || false;
export const enableSignUp = () => global.AppConfig.desktop.auth.signUpEnabled || false;
Expand Down

0 comments on commit 1c0f91d

Please sign in to comment.