(
authMethod: AuthMethod,
options?: { password?: string },
)
| 270 | } |
| 271 | |
| 272 | export async function removeAuthProvider( |
| 273 | authMethod: AuthMethod, |
| 274 | options?: { password?: string }, |
| 275 | ): Promise<ReauthSuccess | ReauthFailed> { |
| 276 | const reauth = await reauthenticate({ |
| 277 | password: options?.password, |
| 278 | excludeMethod: authMethod, |
| 279 | }); |
| 280 | if (reauth.status !== "success") { |
| 281 | return { |
| 282 | status: reauth.status, |
| 283 | message: reauth.message, |
| 284 | }; |
| 285 | } |
| 286 | try { |
| 287 | await unlink(reauth.user, getProviderId(authMethod)); |
| 288 | } catch (e) { |
| 289 | const message = createErrorMessage( |
| 290 | e, |
| 291 | authMethod === "password" |
| 292 | ? "Failed to remove password authentication" |
| 293 | : `Failed to unlink ${getAuthMethodDisplay(authMethod)} account`, |
| 294 | ); |
| 295 | return { |
| 296 | status: "error", |
| 297 | message, |
| 298 | }; |
| 299 | } |
| 300 | return { |
| 301 | status: "success", |
| 302 | message: `${getAuthMethodDisplay(authMethod)} authentication removed`, |
| 303 | user: reauth.user, |
| 304 | }; |
| 305 | } |
| 306 | |
| 307 | export function signOut(): void { |
| 308 | if (!isAuthAvailable()) { |
no test coverage detected