Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto login the user after password is set #14344

2 changes: 1 addition & 1 deletion packages/backend-core/src/security/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import env from "../environment"

export const PASSWORD_MIN_LENGTH = +(env.PASSWORD_MIN_LENGTH || 8)
export const PASSWORD_MIN_LENGTH = +(env.PASSWORD_MIN_LENGTH || 12)
export const PASSWORD_MAX_LENGTH = +(env.PASSWORD_MAX_LENGTH || 512)

export function validatePassword(
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-core/src/security/tests/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PASSWORD_MAX_LENGTH, validatePassword } from "../auth"
describe("auth", () => {
describe("validatePassword", () => {
it("a valid password returns successful", () => {
expect(validatePassword("password")).toEqual({ valid: true })
expect(validatePassword("password123!")).toEqual({ valid: true })
})

it.each([
Expand All @@ -14,7 +14,7 @@ describe("auth", () => {
])("%s returns unsuccessful", (_, password) => {
expect(validatePassword(password as string)).toEqual({
valid: false,
error: "Password invalid. Minimum 8 characters.",
error: "Password invalid. Minimum 12 characters.",
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
_id: userId,
userId,
email: newEmail(),
password: "password",
password: "password123!",
roles: { app_test: "admin" },
firstName: generator.first(),
lastName: generator.last(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
notifications.error("Failed to update password")
}
}

const handleKeydown = evt => {
if (evt.key === "Enter" && !error && password) {
updatePassword()
}
}
</script>

<svelte:window on:keydown={handleKeydown} />
<ModalContent
title="Update password"
confirmText="Update password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

let password = null
const validation = createValidationStore()
validation.addValidatorType("password", "password", true, { minLength: 8 })
validation.addValidatorType("password", "password", true, { minLength: 12 })
$: validation.observe("password", password)

const Step = { CONFIG: "config", SET_PASSWORD: "set_password" }
Expand Down
21 changes: 18 additions & 3 deletions packages/builder/src/pages/builder/admin/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,25 @@
await API.createAdminUser(adminUser)
notifications.success("Admin user created")
await admin.init()
await auth.login({
username: formData?.email.trim(),
password: formData?.password,
})
$goto("../portal")
} catch (error) {
submitted = false
notifications.error(error.message || "Failed to create admin user")
}
}

const handleKeydown = evt => {
if (evt.key === "Enter") {
save()
}
}
</script>

<svelte:window on:keydown={handleKeydown} />
<TestimonialPage>
<Layout gap="M" noPadding>
<Layout justifyItems="center" noPadding>
Expand Down Expand Up @@ -83,9 +94,13 @@
validate={() => {
let fieldError = {}

fieldError["password"] = !formData.password
? "Please enter a password"
: undefined
if (!formData.password) {
fieldError["password"] = "Please enter a password"
} else if (formData.password.length < 12) {
melohagan marked this conversation as resolved.
Show resolved Hide resolved
fieldError["password"] = "Password must be at least 12 characters"
} else {
fieldError["password"] = undefined
}

fieldError["confirmationPassword"] =
!passwordsMatch(
Expand Down
11 changes: 9 additions & 2 deletions packages/builder/src/pages/builder/invite/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@
notifications.error("Error getting invite config")
}
})

const handleKeydown = evt => {
if (evt.key === "Enter") {
acceptInvite()
}
}
</script>

<svelte:window on:keydown={handleKeydown} />
{#if loaded}
<TestimonialPage>
<Layout gap="M" noPadding>
Expand Down Expand Up @@ -154,8 +161,8 @@
function validatePassword() {
if (!formData.password) {
return "Please enter a password"
} else if (formData.password.length < 8) {
return "Please enter at least 8 characters"
} else if (formData.password.length < 12) {
return "Please enter at least 12 characters"
}
return undefined
}
Expand Down
Loading