-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add auth password-login, pull, and push commands #422
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a622c90
feat: add `auth password-login` command
moranshe-max 243fb9d
feat: make password-login non-interactive with --enable/--disable flags
moranshe-max 08ec58f
refactor: move auth-config to resources pattern with pull/push commands
moranshe-max 1050871
fix: migrate auth commands to Base44Command pattern
moranshe-max c26df42
refactor: address PR review feedback on auth-config module
moranshe-max 245862f
refactor: restore resource.ts for auth-config, use Resource<T> interf…
moranshe-max 6d96b8e
fix: adapt auth commands to new CLIContext action signature
moranshe-max 963f62f
chore: hide auth command from top-level help
moranshe-max File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Command } from "commander"; | ||
| import { getPasswordLoginCommand } from "./password-login.js"; | ||
| import { getAuthPullCommand } from "./pull.js"; | ||
| import { getAuthPushCommand } from "./push.js"; | ||
|
|
||
| export function getAuthCommand(): Command { | ||
| return new Command("auth") | ||
| .description("Manage app authentication settings") | ||
| .addCommand(getPasswordLoginCommand()) | ||
| .addCommand(getAuthPullCommand()) | ||
| .addCommand(getAuthPushCommand()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { dirname, join } from "node:path"; | ||
| import type { Command } from "commander"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command, runTask } from "@/cli/utils/index.js"; | ||
| import { InvalidInputError } from "@/core/errors.js"; | ||
| import { readProjectConfig } from "@/core/project/index.js"; | ||
| import { | ||
| DEFAULT_AUTH_CONFIG, | ||
| hasAnyLoginMethod, | ||
| readAuthConfig, | ||
| writeAuthConfig, | ||
| } from "@/core/resources/auth-config/index.js"; | ||
|
|
||
| function validateAction( | ||
| action: string, | ||
| ): asserts action is "enable" | "disable" { | ||
| if (action !== "enable" && action !== "disable") { | ||
| throw new InvalidInputError( | ||
| `Invalid action "${action}". Must be "enable" or "disable".`, | ||
| { | ||
| hints: [ | ||
| { | ||
| message: "Enable password auth: base44 auth password-login enable", | ||
| command: "base44 auth password-login enable", | ||
| }, | ||
| { | ||
| message: | ||
| "Disable password auth: base44 auth password-login disable", | ||
| command: "base44 auth password-login disable", | ||
| }, | ||
| ], | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async function passwordLoginAction( | ||
| { log }: CLIContext, | ||
| action: string, | ||
| ): Promise<RunCommandResult> { | ||
| validateAction(action); | ||
|
|
||
| const shouldEnable = action === "enable"; | ||
| const { project } = await readProjectConfig(); | ||
|
|
||
| const configDir = dirname(project.configPath); | ||
| const authDir = join(configDir, project.authDir); | ||
|
|
||
| const updated = await runTask("Updating local auth config", async () => { | ||
| const current = (await readAuthConfig(authDir)) ?? DEFAULT_AUTH_CONFIG; | ||
| const merged = { ...current, enableUsernamePassword: shouldEnable }; | ||
| await writeAuthConfig(authDir, merged); | ||
| return merged; | ||
| }); | ||
|
|
||
| if (!shouldEnable && !hasAnyLoginMethod(updated)) { | ||
| log.warn( | ||
| "Disabling password auth will leave no login methods enabled. Users will be locked out.", | ||
| ); | ||
| } | ||
|
|
||
| const newStatus = shouldEnable ? "enabled" : "disabled"; | ||
| return { | ||
| outroMessage: `Username & password authentication ${newStatus} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`, | ||
| }; | ||
| } | ||
|
|
||
| export function getPasswordLoginCommand(): Command { | ||
| return new Base44Command("password-login") | ||
| .description("Enable or disable username & password authentication") | ||
| .argument("<enable|disable>", "enable or disable password authentication") | ||
| .action(passwordLoginAction); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { dirname, join } from "node:path"; | ||
| import type { Command } from "commander"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command, runTask } from "@/cli/utils/index.js"; | ||
| import { readProjectConfig } from "@/core/project/index.js"; | ||
| import { | ||
| pullAuthConfig, | ||
| writeAuthConfig, | ||
| } from "@/core/resources/auth-config/index.js"; | ||
|
|
||
| async function pullAuthAction({ log }: CLIContext): Promise<RunCommandResult> { | ||
| const { project } = await readProjectConfig(); | ||
|
|
||
| const configDir = dirname(project.configPath); | ||
| const authDir = join(configDir, project.authDir); | ||
|
|
||
| const remoteConfig = await runTask( | ||
| "Fetching auth config from Base44", | ||
| async () => { | ||
| return await pullAuthConfig(); | ||
| }, | ||
| { | ||
| successMessage: "Auth config fetched successfully", | ||
| errorMessage: "Failed to fetch auth config", | ||
| }, | ||
| ); | ||
|
|
||
| const { written } = await runTask( | ||
| "Syncing auth config file", | ||
| async () => { | ||
| return await writeAuthConfig(authDir, remoteConfig); | ||
| }, | ||
| { | ||
| successMessage: "Auth config file synced successfully", | ||
| errorMessage: "Failed to sync auth config file", | ||
| }, | ||
| ); | ||
|
|
||
| if (written) { | ||
| log.success("Auth config written to local file"); | ||
| } else { | ||
| log.info("Auth config is already up to date"); | ||
| } | ||
|
|
||
| return { | ||
| outroMessage: `Pulled auth config to ${authDir} (overwrites local file)`, | ||
| }; | ||
| } | ||
|
|
||
| export function getAuthPullCommand(): Command { | ||
| return new Base44Command("pull") | ||
| .description("Pull auth config from Base44 to local file") | ||
| .action(pullAuthAction); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { confirm, isCancel } from "@clack/prompts"; | ||
| import type { Command } from "commander"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command, runTask } from "@/cli/utils/index.js"; | ||
| import { InvalidInputError } from "@/core/errors.js"; | ||
| import { readProjectConfig } from "@/core/project/index.js"; | ||
| import { | ||
| hasAnyLoginMethod, | ||
| pushAuthConfig, | ||
| } from "@/core/resources/auth-config/index.js"; | ||
|
|
||
| interface PushAuthOptions { | ||
| yes?: boolean; | ||
| } | ||
|
|
||
| async function pushAuthAction( | ||
| { isNonInteractive, log }: CLIContext, | ||
| options: PushAuthOptions, | ||
| ): Promise<RunCommandResult> { | ||
| const { authConfig } = await readProjectConfig(); | ||
|
|
||
| if (authConfig.length === 0) { | ||
| log.info("No local auth config found"); | ||
| return { | ||
| outroMessage: | ||
| "No auth config to push. Run `base44 auth pull` to fetch the remote config first.", | ||
| }; | ||
| } | ||
|
|
||
| if (!hasAnyLoginMethod(authConfig[0])) { | ||
| log.warn( | ||
| "This config has no login methods enabled. Pushing it will lock out all users.", | ||
| ); | ||
| } | ||
|
|
||
| if (!options.yes) { | ||
| if (isNonInteractive) { | ||
| throw new InvalidInputError("--yes is required in non-interactive mode"); | ||
| } | ||
|
|
||
| const shouldPush = await confirm({ | ||
| message: "Push auth config to Base44?", | ||
| }); | ||
|
|
||
| if (isCancel(shouldPush) || !shouldPush) { | ||
| return { outroMessage: "Push cancelled" }; | ||
| } | ||
| } | ||
|
|
||
| await runTask( | ||
| "Pushing auth config to Base44", | ||
| async () => { | ||
| return await pushAuthConfig(authConfig[0] ?? null); | ||
| }, | ||
| { | ||
| successMessage: "Auth config pushed successfully", | ||
| errorMessage: "Failed to push auth config", | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| outroMessage: "Auth config pushed to Base44", | ||
| }; | ||
| } | ||
|
|
||
| export function getAuthPushCommand(): Command { | ||
| return new Base44Command("push") | ||
| .description("Push local auth config to Base44") | ||
kfirstri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .option("-y, --yes", "Skip confirmation prompt") | ||
| .action(pushAuthAction); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might worth adding some text about overwriting existing file