| 50 | } |
| 51 | |
| 52 | export async function whoAmI( |
| 53 | options?: WhoamiCommandOptions, |
| 54 | embedded: boolean = false |
| 55 | ): Promise<WhoAmIResult> { |
| 56 | if (!embedded) { |
| 57 | intro(`Displaying your account details [${options?.profile ?? "default"}]`); |
| 58 | } |
| 59 | |
| 60 | const loadingSpinner = spinner(); |
| 61 | loadingSpinner.start("Checking your account details"); |
| 62 | |
| 63 | const authentication = await isLoggedIn(options?.profile); |
| 64 | |
| 65 | if (!authentication.ok) { |
| 66 | if (authentication.error === "fetch failed") { |
| 67 | loadingSpinner.stop("Fetch failed. Platform down?"); |
| 68 | } else { |
| 69 | if (embedded) { |
| 70 | loadingSpinner.stop( |
| 71 | `Failed to check account details. You may want to run \`trigger.dev logout --profile ${ |
| 72 | options?.profile ?? "default" |
| 73 | }\` and try again.` |
| 74 | ); |
| 75 | } else { |
| 76 | loadingSpinner.stop( |
| 77 | `You must login first. Use \`trigger.dev login --profile ${ |
| 78 | options?.profile ?? "default" |
| 79 | }\` to login.` |
| 80 | ); |
| 81 | outro(`Whoami failed: ${authentication.error}`); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return { |
| 86 | success: false, |
| 87 | error: authentication.error, |
| 88 | }; |
| 89 | } |
| 90 | |
| 91 | const apiClient = new CliApiClient(authentication.auth.apiUrl, authentication.auth.accessToken); |
| 92 | const userData = await apiClient.whoAmI(); |
| 93 | |
| 94 | if (!userData.success) { |
| 95 | loadingSpinner.stop("Error getting your account details"); |
| 96 | logger.error(userData.error); |
| 97 | return { |
| 98 | success: false, |
| 99 | error: userData.error, |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | if (!embedded) { |
| 104 | loadingSpinner.stop("Retrieved your account details"); |
| 105 | note( |
| 106 | `User ID: ${userData.data.userId} |
| 107 | Email: ${userData.data.email} |
| 108 | URL: ${chalkLink(authentication.auth.apiUrl)} |
| 109 | `, |