Skip to content

Commit

Permalink
feat: auto login (#179)
Browse files Browse the repository at this point in the history
* feat: automatically present login when unauthenticated and command requires authentication

* chore: changeset
  • Loading branch information
field123 authored Jan 25, 2024
1 parent fce362c commit 5e4eec7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-fans-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"composable-cli": patch
---

automatically present login when unauthenticated and command requires authentication
48 changes: 21 additions & 27 deletions packages/composable-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
# `Beta` Elastic Path Composable CLI
<p align="center">

### This package is not feature complete and is work in progress.
<a href="https://www.elasticpath.com/">

This package contains the executable for running [Elastic Path Commerce Cloud](https://www.elasticpath.com/) Schematics.
<img src="https://github.com/elasticpath/mason/assets/3082064/8be38417-6b96-4228-ba6e-e5472e049b27" height="96">

## Installation
<h3 align="center">Elastic Path</h3>

`yarn global add composable-cli` or `npm install -g composable-cli`
</a>

## Generating a storefront
<p align="center">We help commerce leaders deliver extraordinary shopping experiences.</p>

### Login to Elastic Path
</p>

```bash
composable-cli login
```
# `Beta` Elastic Path Composable CLI

### Generate a D2C (Direct-to-consumer) storefront
🚨 **This is an early release of this package some bugs and issues should be expected.** 🚨

```bash
composable-cli generate d2c my-storefront
```
Elastic Path excels in delivering highly configurable eCommerce experiences by leveraging modular services, making the implementation of complex experiences and business models seamless.

Select your Elastic Path store from the list of stores.
Composable CLI streamlines the initial setup process for Elastic Path, making it effortless to get started.

### Getting help
## Installation

```bash
composable-cli --help
```
To install the latest version of Composable CLI, run the following command:

`npm install -g composable-cli`

## Integrations
## Usage

### Configuring Algolia integration
To generate a storefront, run the following command:

```bash
composable-cli int algolia
ep generate
```

## Elastic Path Payments Setup
When issuing commands with Composable CLI you can use either `ep` or `composable-cli` as one is just a alias for the other.

### Configuring Elastic Path Payments
## Documentation

```bash
composable-cli p ep-payments
```
To find out more about how to use Composable CLI, check out the [documentation](https://composable-frontend-docs.vercel.app/docs/category/composable-cli).
11 changes: 5 additions & 6 deletions packages/composable-cli/src/commands/login/login-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export function createAuthenticationMiddleware(
) {
const { store } = ctx

if (isAuthenticated(store) || !args.interactive) {
const isAuthCommand = args._.some(
(arg) => arg === "login" || arg === "logout",
)

if (isAuthenticated(store) || !args.interactive || isAuthCommand) {
return
}

Expand Down Expand Up @@ -199,11 +203,6 @@ export function createLoginCommandHandler(
],
})

// await render(
// React.createElement(WelcomeNote, {
// name: userProfileResponse.data.data.name,
// }),
// )
return {
success: true,
data: {},
Expand Down
2 changes: 0 additions & 2 deletions packages/composable-cli/src/commands/store/store-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
switchUserStore,
} from "../../util/build-store-prompts"
import inquirer from "inquirer"
import { createAuthenticationMiddleware } from "../login/login-command"
import { userStoreResponseSchema } from "../../lib/stores/stores-schema"
import { Result } from "../../types/results"
import {
Expand All @@ -39,7 +38,6 @@ export function createStoreCommand(
describe: "interact with Elasticpath store",
builder: (yargs) => {
return yargs
.middleware(createAuthenticationMiddleware(ctx))
.command(createSetStoreCommand(ctx))
.fail(false)
.demandCommand(1)
Expand Down
6 changes: 5 additions & 1 deletion packages/composable-cli/src/composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import "symbol-observable"
import { ProcessOutput } from "@angular-devkit/core/node"
import yargs from "yargs/yargs"
import { createLoginCommand } from "./commands/login/login-command"
import {
createAuthenticationMiddleware,
createLoginCommand,
} from "./commands/login/login-command"
import { createConfigCommand } from "./commands/config/config-command"
import { createCommandContext } from "./util/command"
import { createLogoutCommand } from "./commands/logout/logout-command"
Expand Down Expand Up @@ -62,6 +65,7 @@ export async function main({
.middleware(createLoggerMiddleware(commandContext))
.middleware(createConfigMiddleware(commandContext))
.middleware(createUUIDMiddleware(commandContext))
.middleware(createAuthenticationMiddleware(commandContext))
.middleware(createOptInProductInsightsMiddleware(commandContext))
.middleware(createPostHogMiddleware(commandContext))
.middleware(createEpClientMiddleware(commandContext))
Expand Down

0 comments on commit 5e4eec7

Please sign in to comment.