Skip to content

Commit ecc8fbd

Browse files
fix: Login workflow depending on smtp is configured (#3307)
1 parent c9b628e commit ecc8fbd

File tree

7 files changed

+121
-100
lines changed

7 files changed

+121
-100
lines changed

apiserver/.env.example

-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ OPENAI_API_BASE="https://api.openai.com/v1" # deprecated
3939
OPENAI_API_KEY="sk-" # deprecated
4040
GPT_ENGINE="gpt-3.5-turbo" # deprecated
4141

42-
# Github
43-
GITHUB_CLIENT_SECRET="" # For fetching release notes
44-
4542
# Settings related to Docker
4643
DOCKERIZED=1 # deprecated
4744

apiserver/plane/app/views/config.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class ConfigurationEndpoint(BaseAPIView):
2020
]
2121

2222
def get(self, request):
23-
2423
# Get all the configuration
2524
(
2625
GOOGLE_CLIENT_ID,
@@ -90,8 +89,12 @@ def get(self, request):
9089

9190
data = {}
9291
# Authentication
93-
data["google_client_id"] = GOOGLE_CLIENT_ID if GOOGLE_CLIENT_ID and GOOGLE_CLIENT_ID != "\"\"" else None
94-
data["github_client_id"] = GITHUB_CLIENT_ID if GITHUB_CLIENT_ID and GITHUB_CLIENT_ID != "\"\"" else None
92+
data["google_client_id"] = (
93+
GOOGLE_CLIENT_ID if GOOGLE_CLIENT_ID and GOOGLE_CLIENT_ID != '""' else None
94+
)
95+
data["github_client_id"] = (
96+
GITHUB_CLIENT_ID if GITHUB_CLIENT_ID and GITHUB_CLIENT_ID != '""' else None
97+
)
9598
data["github_app_name"] = GITHUB_APP_NAME
9699
data["magic_login"] = (
97100
bool(EMAIL_HOST_USER) and bool(EMAIL_HOST_PASSWORD)
@@ -114,7 +117,9 @@ def get(self, request):
114117
# File size settings
115118
data["file_size_limit"] = float(os.environ.get("FILE_SIZE_LIMIT", 5242880))
116119

117-
# is self managed
118-
data["is_self_managed"] = bool(int(os.environ.get("IS_SELF_MANAGED", "1")))
120+
# is smtp configured
121+
data["is_smtp_configured"] = not (
122+
bool(EMAIL_HOST_USER) and bool(EMAIL_HOST_PASSWORD)
123+
)
119124

120125
return Response(data, status=status.HTTP_200_OK)

packages/types/src/app.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
export interface IAppConfig {
42
email_password_login: boolean;
53
file_size_limit: number;
@@ -12,5 +10,5 @@ export interface IAppConfig {
1210
posthog_host: string | null;
1311
has_openai_configured: boolean;
1412
has_unsplash_configured: boolean;
15-
is_self_managed: boolean;
13+
is_smtp_configured: boolean;
1614
}

web/components/account/sign-in-forms/email-form.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { useEffect } from "react";
22
import { Controller, useForm } from "react-hook-form";
33
import { XCircle } from "lucide-react";
4+
import { observer } from "mobx-react-lite";
45
// services
56
import { AuthService } from "services/auth.service";
67
// hooks
78
import useToast from "hooks/use-toast";
9+
import { useApplication } from "hooks/store";
810
// ui
911
import { Button, Input } from "@plane/ui";
1012
// helpers
@@ -25,11 +27,13 @@ type TEmailFormValues = {
2527

2628
const authService = new AuthService();
2729

28-
export const EmailForm: React.FC<Props> = (props) => {
30+
export const EmailForm: React.FC<Props> = observer((props) => {
2931
const { handleStepChange, updateEmail } = props;
30-
32+
// hooks
3133
const { setToastAlert } = useToast();
32-
34+
const {
35+
config: { envConfig },
36+
} = useApplication();
3337
const {
3438
control,
3539
formState: { errors, isSubmitting, isValid },
@@ -54,9 +58,11 @@ export const EmailForm: React.FC<Props> = (props) => {
5458
await authService
5559
.emailCheck(payload)
5660
.then((res) => {
57-
// if the password has been autoset, send the user to magic sign-in
58-
if (res.is_password_autoset) handleStepChange(ESignInSteps.UNIQUE_CODE);
59-
// if the password has not been autoset, send them to password sign-in
61+
// if the password has been auto set, send the user to magic sign-in
62+
if (res.is_password_autoset && envConfig?.is_smtp_configured) {
63+
handleStepChange(ESignInSteps.UNIQUE_CODE);
64+
}
65+
// if the password has not been auto set, send them to password sign-in
6066
else handleStepChange(ESignInSteps.PASSWORD);
6167
})
6268
.catch((err) =>
@@ -119,4 +125,4 @@ export const EmailForm: React.FC<Props> = (props) => {
119125
</form>
120126
</>
121127
);
122-
};
128+
});

web/components/account/sign-in-forms/password.tsx

+26-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { XCircle } from "lucide-react";
66
import { AuthService } from "services/auth.service";
77
// hooks
88
import useToast from "hooks/use-toast";
9+
import { useApplication } from "hooks/store";
910
// ui
1011
import { Button, Input } from "@plane/ui";
1112
// helpers
@@ -14,12 +15,14 @@ import { checkEmailValidity } from "helpers/string.helper";
1415
import { IPasswordSignInData } from "@plane/types";
1516
// constants
1617
import { ESignInSteps } from "components/account";
18+
import { observer } from "mobx-react-lite";
1719

1820
type Props = {
1921
email: string;
2022
updateEmail: (email: string) => void;
2123
handleStepChange: (step: ESignInSteps) => void;
2224
handleSignInRedirection: () => Promise<void>;
25+
handleEmailClear: () => void;
2326
};
2427

2528
type TPasswordFormValues = {
@@ -34,13 +37,16 @@ const defaultValues: TPasswordFormValues = {
3437

3538
const authService = new AuthService();
3639

37-
export const PasswordForm: React.FC<Props> = (props) => {
38-
const { email, updateEmail, handleStepChange, handleSignInRedirection } = props;
40+
export const PasswordForm: React.FC<Props> = observer((props) => {
41+
const { email, updateEmail, handleStepChange, handleSignInRedirection, handleEmailClear } = props;
3942
// states
4043
const [isSendingUniqueCode, setIsSendingUniqueCode] = useState(false);
4144
const [isSendingResetPasswordLink, setIsSendingResetPasswordLink] = useState(false);
4245
// toast alert
4346
const { setToastAlert } = useToast();
47+
const {
48+
config: { envConfig },
49+
} = useApplication();
4450
// form info
4551
const {
4652
control,
@@ -157,11 +163,12 @@ export const PasswordForm: React.FC<Props> = (props) => {
157163
hasError={Boolean(errors.email)}
158164
placeholder="[email protected]"
159165
className="h-[46px] w-full border border-onboarding-border-100 pr-12 placeholder:text-onboarding-text-400"
166+
disabled
160167
/>
161168
{value.length > 0 && (
162169
<XCircle
163170
className="absolute right-3 h-5 w-5 stroke-custom-text-400 hover:cursor-pointer"
164-
onClick={() => onChange("")}
171+
onClick={handleEmailClear}
165172
/>
166173
)}
167174
</div>
@@ -199,26 +206,28 @@ export const PasswordForm: React.FC<Props> = (props) => {
199206
</button>
200207
</div>
201208
</div>
202-
<div className="grid gap-2.5 sm:grid-cols-2">
203-
<Button
204-
type="button"
205-
onClick={handleSendUniqueCode}
206-
variant="primary"
207-
className="w-full"
208-
size="xl"
209-
loading={isSendingUniqueCode}
210-
>
211-
{isSendingUniqueCode ? "Sending code" : "Use unique code"}
212-
</Button>
209+
<div className="flex gap-4">
210+
{envConfig && envConfig.is_smtp_configured && (
211+
<Button
212+
type="button"
213+
onClick={handleSendUniqueCode}
214+
variant="outline-primary"
215+
className="w-full"
216+
size="xl"
217+
loading={isSendingUniqueCode}
218+
>
219+
{isSendingUniqueCode ? "Sending code" : "Use unique code"}
220+
</Button>
221+
)}
213222
<Button
214223
type="submit"
215-
variant="outline-primary"
224+
variant="primary"
216225
className="w-full"
217226
size="xl"
218227
disabled={!isValid}
219228
loading={isSubmitting}
220229
>
221-
Go to workspace
230+
Continue
222231
</Button>
223232
</div>
224233
<p className="text-xs text-onboarding-text-200">
@@ -230,4 +239,4 @@ export const PasswordForm: React.FC<Props> = (props) => {
230239
</form>
231240
</>
232241
);
233-
};
242+
});

web/components/account/sign-in-forms/root.tsx

+67-64
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
OAuthOptions,
1414
OptionalSetPasswordForm,
1515
CreatePasswordForm,
16-
SelfHostedSignInForm,
1716
} from "components/account";
1817

1918
export enum ESignInSteps {
@@ -45,69 +44,73 @@ export const SignInRoot = observer(() => {
4544
return (
4645
<>
4746
<div className="mx-auto flex flex-col">
48-
{envConfig?.is_self_managed ? (
49-
<SelfHostedSignInForm
50-
email={email}
51-
updateEmail={(newEmail) => setEmail(newEmail)}
52-
handleSignInRedirection={handleRedirection}
53-
/>
54-
) : (
55-
<>
56-
{signInStep === ESignInSteps.EMAIL && (
57-
<EmailForm
58-
handleStepChange={(step) => setSignInStep(step)}
59-
updateEmail={(newEmail) => setEmail(newEmail)}
60-
/>
61-
)}
62-
{signInStep === ESignInSteps.PASSWORD && (
63-
<PasswordForm
64-
email={email}
65-
updateEmail={(newEmail) => setEmail(newEmail)}
66-
handleStepChange={(step) => setSignInStep(step)}
67-
handleSignInRedirection={handleRedirection}
68-
/>
69-
)}
70-
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
71-
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
72-
)}
73-
{signInStep === ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD && (
74-
<UniqueCodeForm
75-
email={email}
76-
updateEmail={(newEmail) => setEmail(newEmail)}
77-
handleStepChange={(step) => setSignInStep(step)}
78-
handleSignInRedirection={handleRedirection}
79-
submitButtonLabel="Go to workspace"
80-
showTermsAndConditions
81-
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
82-
/>
83-
)}
84-
{signInStep === ESignInSteps.UNIQUE_CODE && (
85-
<UniqueCodeForm
86-
email={email}
87-
updateEmail={(newEmail) => setEmail(newEmail)}
88-
handleStepChange={(step) => setSignInStep(step)}
89-
handleSignInRedirection={handleRedirection}
90-
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
91-
/>
92-
)}
93-
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
94-
<OptionalSetPasswordForm
95-
email={email}
96-
handleStepChange={(step) => setSignInStep(step)}
97-
handleSignInRedirection={handleRedirection}
98-
isOnboarded={isOnboarded}
99-
/>
100-
)}
101-
{signInStep === ESignInSteps.CREATE_PASSWORD && (
102-
<CreatePasswordForm
103-
email={email}
104-
handleStepChange={(step) => setSignInStep(step)}
105-
handleSignInRedirection={handleRedirection}
106-
isOnboarded={isOnboarded}
107-
/>
108-
)}
109-
</>
110-
)}
47+
<>
48+
{signInStep === ESignInSteps.EMAIL && (
49+
<EmailForm
50+
handleStepChange={(step) => setSignInStep(step)}
51+
updateEmail={(newEmail) => setEmail(newEmail)}
52+
/>
53+
)}
54+
{signInStep === ESignInSteps.PASSWORD && (
55+
<PasswordForm
56+
email={email}
57+
updateEmail={(newEmail) => setEmail(newEmail)}
58+
handleStepChange={(step) => setSignInStep(step)}
59+
handleEmailClear={() => {
60+
setEmail("");
61+
setSignInStep(ESignInSteps.EMAIL);
62+
}}
63+
handleSignInRedirection={handleRedirection}
64+
/>
65+
)}
66+
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
67+
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
68+
)}
69+
{signInStep === ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD && (
70+
<UniqueCodeForm
71+
email={email}
72+
updateEmail={(newEmail) => setEmail(newEmail)}
73+
handleStepChange={(step) => setSignInStep(step)}
74+
handleSignInRedirection={handleRedirection}
75+
submitButtonLabel="Go to workspace"
76+
showTermsAndConditions
77+
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
78+
handleEmailClear={() => {
79+
setEmail("");
80+
setSignInStep(ESignInSteps.EMAIL);
81+
}}
82+
/>
83+
)}
84+
{signInStep === ESignInSteps.UNIQUE_CODE && (
85+
<UniqueCodeForm
86+
email={email}
87+
updateEmail={(newEmail) => setEmail(newEmail)}
88+
handleStepChange={(step) => setSignInStep(step)}
89+
handleSignInRedirection={handleRedirection}
90+
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
91+
handleEmailClear={() => {
92+
setEmail("");
93+
setSignInStep(ESignInSteps.EMAIL);
94+
}}
95+
/>
96+
)}
97+
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
98+
<OptionalSetPasswordForm
99+
email={email}
100+
handleStepChange={(step) => setSignInStep(step)}
101+
handleSignInRedirection={handleRedirection}
102+
isOnboarded={isOnboarded}
103+
/>
104+
)}
105+
{signInStep === ESignInSteps.CREATE_PASSWORD && (
106+
<CreatePasswordForm
107+
email={email}
108+
handleStepChange={(step) => setSignInStep(step)}
109+
handleSignInRedirection={handleRedirection}
110+
isOnboarded={isOnboarded}
111+
/>
112+
)}
113+
</>
111114
</div>
112115
{isOAuthEnabled && !OAUTH_HIDDEN_STEPS.includes(signInStep) && (
113116
<OAuthOptions handleSignInRedirection={handleRedirection} />

web/components/account/sign-in-forms/unique-code.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Props = {
2525
submitButtonLabel?: string;
2626
showTermsAndConditions?: boolean;
2727
updateUserOnboardingStatus: (value: boolean) => void;
28+
handleEmailClear: () => void;
2829
};
2930

3031
type TUniqueCodeFormValues = {
@@ -50,6 +51,7 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
5051
submitButtonLabel = "Continue",
5152
showTermsAndConditions = false,
5253
updateUserOnboardingStatus,
54+
handleEmailClear,
5355
} = props;
5456
// states
5557
const [isRequestingNewCode, setIsRequestingNewCode] = useState(false);
@@ -183,11 +185,12 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
183185
hasError={Boolean(errors.email)}
184186
placeholder="[email protected]"
185187
className="h-[46px] w-full border border-onboarding-border-100 pr-12 placeholder:text-onboarding-text-400"
188+
disabled
186189
/>
187190
{value.length > 0 && (
188191
<XCircle
189192
className="absolute right-3 h-5 w-5 stroke-custom-text-400 hover:cursor-pointer"
190-
onClick={() => onChange("")}
193+
onClick={handleEmailClear}
191194
/>
192195
)}
193196
</div>

0 commit comments

Comments
 (0)