()
| 216 | } |
| 217 | |
| 218 | private async loadCredentials(): Promise<AuthCredentials | null> { |
| 219 | const credentialsJson = await this.context.secrets.get(this.authCredentialsKey) |
| 220 | if (!credentialsJson) return null |
| 221 | |
| 222 | try { |
| 223 | const parsedJson = JSON.parse(credentialsJson) |
| 224 | const credentials = authCredentialsSchema.parse(parsedJson) |
| 225 | |
| 226 | // Migration: If no organizationId but we have userInfo, add it |
| 227 | if (credentials.organizationId === undefined && this.userInfo?.organizationId) { |
| 228 | credentials.organizationId = this.userInfo.organizationId |
| 229 | await this.storeCredentials(credentials) |
| 230 | this.log("[auth] Migrated credentials with organizationId") |
| 231 | } |
| 232 | |
| 233 | return credentials |
| 234 | } catch (error) { |
| 235 | if (error instanceof z.ZodError) { |
| 236 | this.log("[auth] Invalid credentials format:", error.errors) |
| 237 | } else { |
| 238 | this.log("[auth] Failed to parse stored credentials:", error) |
| 239 | } |
| 240 | return null |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | private async clearCredentials(): Promise<void> { |
| 245 | await this.context.secrets.delete(this.authCredentialsKey) |
no test coverage detected