Raw
1 import { Table } from "docs-ui"
2
3 export const metadata = {
4 title: `login Command - Medusa Cloud CLI Reference`,
5 }
6
7 # {metadata.title}
8
9 Authenticate with Cloud and store your credentials on disk. This is essential before running other Cloud CLI commands.
10
11 ```bash
12 mcloud login
13 ```
14
15 Running the command without options opens a browser window where you complete
16 the login flow. After a successful login, your credentials are stored on your
17 machine and reused automatically by subsequent CLI commands.
18
19 When the `MCLOUD_TOKEN` environment variable is set, `mcloud login` cannot be
20 called. The CLI rejects it because the environment variable takes
21 precedence. Use `mcloud login` only when `MCLOUD_TOKEN` is not set.
22
23 ## Options
24
25 <Table>
26 <Table.Header>
27 <Table.Row>
28 <Table.HeaderCell>
29 Option
30 </Table.HeaderCell>
31 <Table.HeaderCell>
32 Description
33 </Table.HeaderCell>
34 </Table.Row>
35 </Table.Header>
36 <Table.Body>
37 <Table.Row>
38 <Table.Cell>
39
40 `-t <key>`, `--token <key>`
41
42 </Table.Cell>
43 <Table.Cell>
44
45 A Cloud access key. Stores the key to disk without opening a browser.
46 Use this on developer machines or headless servers where you want
47 stored credentials. Either use this option or `MCLOUD_TOKEN` for
48 non-interactive authentication.
49
50 </Table.Cell>
51 </Table.Row>
52 <Table.Row>
53 <Table.Cell>
54
55 `--json`
56
57 </Table.Cell>
58 <Table.Cell>
59
60 Print the result as JSON instead of formatted text. Defaults to `false`.
61
62 </Table.Cell>
63 </Table.Row>
64 </Table.Body>
65 </Table>
66
67 ## Authenticate Locally
68
69 After installing the CLI, run `mcloud login` without setting `MCLOUD_TOKEN`. A browser will open to login with your Cloud account. After you complete the login flow, your credentials are stored locally and used automatically by subsequent commands.
70
71 ```bash
72 mcloud login
73 ```
74
75 After login, the CLI infers and saves a default context (organization, project, and the production environment if available) so subsequent commands can run without `--organization`, `--project`, or `--environment` flags. You can change the active context at any time with [`mcloud use`](../use/page.mdx).
76
77 To log out, run [mcloud logout](../logout/page.mdx) to clear your credentials from disk.
78
79 ---
80
81 ## Non-Interactive Authentication
82
83 If you don't have access to a browser, you prefer non-interactive authentication, or you're using the CLI in CI/CD pipelines and other automated environments, set the `MCLOUD_TOKEN`
84 environment variable to your access key. The CLI reads it directly on every
85 command invocation, and you do not need to call `mcloud login` at all.
86
87 Cloud supports two types of access keys for non-interactive authentication.
88 The type you use determines whether you need to pass `--organization` on
89 commands that scope to an organization.
90
91 - [Personal access key](../../../access-keys/page.mdx#manage-personal-access-keys): Generated from your account settings in the Cloud dashboard. Grants access to every organization you belong to, so you must specify which organization to target by passing `--organization` on every command that requires it, or by setting it once with [`mcloud use --organization <id>`](../use/page.mdx).
92 - [Organization access key](../../../access-keys/page.mdx#manage-organization-access-keys): Generated from an organization's settings in the Cloud dashboard. Scoped to that specific organization, so `--organization` is never required.
93
94 ```bash
95 # Set once in your CI platform as a secret
96 export MCLOUD_TOKEN=sk_123ABC
97 # Then run commands as normal without passing --token or --organization (if using an organization access key)
98 mcloud environments list --project my-store
99 mcloud logs --project my-store --environment production --follow
100 ```
101
102 ### With a Personal Access Key
103
104 Personal access keys require an organization ID. Pass `--organization` on each command, or set it once with `mcloud use --organization <id>` so all subsequent commands use it automatically:
105
106 ```bash
107 # Personal access key set as a secret in your CI platform
108 export MCLOUD_TOKEN=sk_123ABC
109
110 # Persist the active organization in the context configuration
111 mcloud use --organization org_01ABC123
112
113 mcloud environments list --project proj_123
114 mcloud logs --project proj_123 --environment production --follow
115
116 # Switch to a different organization later
117 mcloud use --organization org_01DEF456
118 mcloud environments list --project proj_123
119 ```
120
121 ### With an Organization Access Key
122
123 Organization access keys are already scoped to one organization, so you don't need to set the active organization or pass `--organization` on commands:
124
125 ```bash
126 # Set organization access key as a secret in your CI platform
127 export MCLOUD_TOKEN=sk_123ABC
128
129 mcloud environments list --project proj_123
130 mcloud logs --project proj_123 --environment production --follow
131 ```
132
133 ### Logging Out of Non-Interactive Authentication
134
135 To log out when using `MCLOUD_TOKEN`, unset the environment variable:
136
137 ```bash
138 unset MCLOUD_TOKEN
139 ```
140
141 Subsequent commands will fail until you either set `MCLOUD_TOKEN` again or run `mcloud login` to authenticate with a browser and store credentials on disk.