Skip to content

Commit 60e51bd

Browse files
Use the provided alias for new accounts
1 parent 1433a80 commit 60e51bd

File tree

4 files changed

+14
-40
lines changed

4 files changed

+14
-40
lines changed

packages/cli-kit/src/private/node/session.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,13 @@ async function executeCompleteFlow(applications: OAuthApplications, alias?: stri
301301
outputDebug(outputContent`CLI token received. Exchanging it for application tokens...`)
302302
const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)
303303

304-
const defaultAlias = alias ?? identityToken.userId
305-
const finalAlias = await renderTextPrompt({
306-
message: 'Enter an alias to identify this account',
307-
defaultValue: defaultAlias,
308-
allowEmpty: false,
309-
})
304+
const finalAlias =
305+
alias ??
306+
(await renderTextPrompt({
307+
message: 'Enter an alias to identify this account',
308+
defaultValue: identityToken.userId,
309+
allowEmpty: false,
310+
}))
310311

311312
const session: Session = {
312313
identity: {

packages/cli-kit/src/private/node/session/store.test.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ApplicationToken, Sessions} from './schema.js'
1+
import {Sessions} from './schema.js'
22
import {store, fetch, remove, getSessionAlias, updateSessionAlias, findSessionByAlias} from './store.js'
33
import {getSessions, removeSessions, setSessions, removeCurrentSessionId} from '../conf-store.js'
44
import {identityFqdn} from '../../../public/node/context/fqdn.js'
@@ -232,17 +232,17 @@ describe('session store', () => {
232232
'identity.fqdn.com': {
233233
user1: {
234234
identity: {
235-
...mockSessions['identity.fqdn.com'].user1.identity,
235+
...mockSessions['identity.fqdn.com']!.user1!.identity,
236236
alias: 'Duplicate Alias',
237237
},
238-
applications: mockSessions['identity.fqdn.com'].user1.applications,
238+
applications: mockSessions['identity.fqdn.com']!.user1!.applications,
239239
},
240240
user2: {
241241
identity: {
242-
...mockSessions['identity.fqdn.com'].user2.identity,
242+
...mockSessions['identity.fqdn.com']!.user2!.identity,
243243
alias: 'Duplicate Alias',
244244
},
245-
applications: mockSessions['identity.fqdn.com'].user2.applications,
245+
applications: mockSessions['identity.fqdn.com']!.user2!.applications,
246246
},
247247
},
248248
}
@@ -256,30 +256,3 @@ describe('session store', () => {
256256
})
257257
})
258258
})
259-
260-
function testSession(): Sessions {
261-
const testToken: ApplicationToken = {
262-
accessToken: 'access',
263-
expiresAt: new Date(),
264-
scopes: [],
265-
}
266-
return {
267-
'accounts.shopify.com': {
268-
'1234-5678': {
269-
identity: {
270-
accessToken: 'accessToken',
271-
refreshToken: 'refreshToken',
272-
expiresAt: new Date(),
273-
scopes: ['foo'],
274-
userId: '1234-5678',
275-
alias: '1234-5678',
276-
},
277-
applications: {
278-
adminApi: testToken,
279-
partnersApi: testToken,
280-
storefrontRendererApi: testToken,
281-
},
282-
},
283-
},
284-
}
285-
}

packages/cli/src/cli/commands/auth/logout.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ describe('logs out', () => {
1515

1616
// Then
1717
expect(logout).toHaveBeenCalledOnce()
18-
expect(outputMock.success()).toMatchInlineSnapshot('"Logged out from Shopify"')
18+
expect(outputMock.success()).toMatchInlineSnapshot('"Logged out from all the accounts"')
1919
})
2020
})

packages/cli/src/cli/commands/auth/logout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export default class Logout extends Command {
77

88
async run(): Promise<void> {
99
await logout()
10-
outputSuccess('Logged out from Shopify')
10+
outputSuccess('Logged out from all the accounts')
1111
}
1212
}

0 commit comments

Comments
 (0)