3131 * `kind` field provides a unique string that can be used to brand the error in place of the
3232 * `internalCode`, when rethrowing the error.
3333 */
34- import type * as amplify from '@aws-amplify/auth'
3534import type * as cognito from 'amazon-cognito-identity-js'
3635import * as results from 'ts-results'
3736
@@ -185,7 +184,8 @@ export class Cognito {
185184 */
186185 async signInWithApple ( ) {
187186 this . isSignedIn = true
188- listen . authEventListener ?.( listen . AuthEvent . signIn )
187+ listen . authEventListener ?.( listen . AuthEvent . signInWithRedirect )
188+ listen . authEventListener ?.( listen . AuthEvent . signedIn )
189189 await Promise . resolve ( )
190190 }
191191
@@ -198,7 +198,8 @@ export class Cognito {
198198 */
199199 async signInWithMicrosoft ( ) {
200200 this . isSignedIn = true
201- listen . authEventListener ?.( listen . AuthEvent . signIn )
201+ listen . authEventListener ?.( listen . AuthEvent . signInWithRedirect )
202+ listen . authEventListener ?.( listen . AuthEvent . signedIn )
202203 await Promise . resolve ( )
203204 }
204205
@@ -211,7 +212,8 @@ export class Cognito {
211212 */
212213 async signInWithGoogle ( ) {
213214 this . isSignedIn = true
214- listen . authEventListener ?.( listen . AuthEvent . signIn )
215+ listen . authEventListener ?.( listen . AuthEvent . signInWithRedirect )
216+ listen . authEventListener ?.( listen . AuthEvent . signedIn )
215217 await Promise . resolve ( )
216218 }
217219
@@ -224,7 +226,8 @@ export class Cognito {
224226 */
225227 signInWithGitHub ( ) {
226228 this . isSignedIn = true
227- listen . authEventListener ?.( listen . AuthEvent . signIn )
229+ listen . authEventListener ?.( listen . AuthEvent . signInWithRedirect )
230+ listen . authEventListener ?.( listen . AuthEvent . signedIn )
228231 return Promise . resolve ( {
229232 accessKeyId : 'access key id' ,
230233 sessionToken : 'session token' ,
@@ -245,7 +248,7 @@ export class Cognito {
245248 mockEmail = username
246249 localStorage . setItem ( MOCK_EMAIL_KEY , username )
247250 const result = await results . Result . wrapAsync ( async ( ) => {
248- listen . authEventListener ?.( listen . AuthEvent . signIn )
251+ listen . authEventListener ?.( listen . AuthEvent . signedIn )
249252 return Promise . resolve ( await this . userSession ( ) )
250253 } )
251254 return result
@@ -256,7 +259,7 @@ export class Cognito {
256259 /** Sign out the current user. */
257260 async signOut ( ) {
258261 this . isSignedIn = false
259- listen . authEventListener ?.( listen . AuthEvent . signOut )
262+ listen . authEventListener ?.( listen . AuthEvent . signedOut )
260263 localStorage . removeItem ( MOCK_EMAIL_KEY )
261264 localStorage . removeItem ( MOCK_ORGANIZATION_ID_KEY )
262265 return Promise . resolve ( null )
@@ -301,18 +304,13 @@ export class Cognito {
301304 * component.
302305 */
303306 async changePassword ( oldPassword : string , newPassword : string ) {
304- const cognitoUserResult = await currentAuthenticatedUser ( )
305- if ( cognitoUserResult . ok ) {
306- const result = await results . Result . wrapAsync ( ( ) =>
307- fetch ( 'https://mock-cognito.com/change-password' , {
308- method : 'POST' ,
309- body : JSON . stringify ( { oldPassword, newPassword } ) ,
310- } ) ,
311- )
312- return result . mapErr ( original . intoAmplifyErrorOrThrow )
313- } else {
314- return results . Err ( cognitoUserResult . val )
315- }
307+ const result = await results . Result . wrapAsync ( ( ) =>
308+ fetch ( 'https://mock-cognito.com/change-password' , {
309+ method : 'POST' ,
310+ body : JSON . stringify ( { oldPassword, newPassword } ) ,
311+ } ) ,
312+ )
313+ return result . mapErr ( original . intoAmplifyErrorOrThrow )
316314 }
317315
318316 /** Refresh the current user's session. */
@@ -387,15 +385,3 @@ async function confirmSignUp(_email: string, _code: string) {
387385 result . mapErr ( original . intoAmplifyErrorOrThrow ) . mapErr ( original . intoConfirmSignUpErrorOrThrow ) ,
388386 )
389387}
390-
391- /**
392- * A wrapper around the Amplify "current authenticated user" endpoint that converts known errors
393- * to `AmplifyError`s.
394- */
395- async function currentAuthenticatedUser ( ) {
396- const result = await results . Result . wrapAsync (
397- // The methods are not needed.
398- async ( ) => await Promise . resolve < amplify . CognitoUser > ( { } as unknown as amplify . CognitoUser ) ,
399- )
400- return result . mapErr ( original . intoAmplifyErrorOrThrow )
401- }
0 commit comments