@@ -24,6 +24,7 @@ import { createOAuthError } from '../../../src/providers/cognito/utils/oauth/cre
2424import { signInWithRedirect } from '../../../src/providers/cognito/apis/signInWithRedirect' ;
2525import type { OAuthStore } from '../../../src/providers/cognito/utils/types' ;
2626import { mockAuthConfigWithOAuth } from '../../mockData' ;
27+ import { type AuthPrompt } from '../../../src/types/inputs' ;
2728
2829jest . mock ( '@aws-amplify/core/internals/utils' , ( ) => ( {
2930 ...jest . requireActual ( '@aws-amplify/core/internals/utils' ) ,
@@ -107,6 +108,13 @@ describe('signInWithRedirect', () => {
107108 const mockCodeChallenge = 'code_challenge' ;
108109 const mockToCodeChallenge = jest . fn ( ( ) => mockCodeChallenge ) ;
109110
111+ const promptTypes = [
112+ 'NONE' ,
113+ 'LOGIN' ,
114+ 'CONSENT' ,
115+ 'SELECT_ACCOUNT' ,
116+ ] as const satisfies readonly AuthPrompt [ ] ;
117+
110118 beforeAll ( ( ) => {
111119 mockGenerateState . mockReturnValue ( mockState ) ;
112120 mockGenerateCodeVerifier . mockReturnValue ( {
@@ -189,6 +197,42 @@ describe('signInWithRedirect', () => {
189197 expect ( mockUrlSafeEncode ) . toHaveBeenCalledWith ( expectedCustomState ) ;
190198 } ) ;
191199
200+ it ( 'includes prompt parameter in authorization URL' , async ( ) => {
201+ for ( const prompt of promptTypes ) {
202+ const expectedCustomProvider = 'PieAuth' ;
203+ await signInWithRedirect ( {
204+ provider : { custom : expectedCustomProvider } ,
205+ options : { prompt } ,
206+ } ) ;
207+ const [ oauthUrl ] = mockOpenAuthSession . mock . calls [ 0 ] ;
208+ const cognitoPrompt = prompt . toLowerCase ( ) ;
209+ expect ( oauthUrl ) . toStrictEqual (
210+ `https://oauth.domain.com/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F&response_type=code&client_id=userPoolClientId&identity_provider=${ expectedCustomProvider } &scope=phone%20email%20openid%20profile%20aws.cognito.signin.user.admin&prompt=${ cognitoPrompt } &state=oauth_state&code_challenge=code_challenge&code_challenge_method=S256` ,
211+ ) ;
212+ mockOpenAuthSession . mockClear ( ) ;
213+ }
214+ } ) ;
215+
216+ it ( 'calls assertUserNotAuthenticated based on prompt value' , async ( ) => {
217+ for ( const prompt of promptTypes ) {
218+ const expectedCustomProvider = 'PieAuth' ;
219+ await signInWithRedirect ( {
220+ provider : { custom : expectedCustomProvider } ,
221+ options : { prompt } ,
222+ } ) ;
223+
224+ expect ( mockAssertUserNotAuthenticated ) . not . toHaveBeenCalled ( ) ;
225+
226+ mockAssertUserNotAuthenticated . mockClear ( ) ;
227+ mockOpenAuthSession . mockClear ( ) ;
228+ }
229+
230+ // Test no options at all
231+ await signInWithRedirect ( ) ;
232+ expect ( mockAssertUserNotAuthenticated ) . toHaveBeenCalled ( ) ;
233+ mockAssertUserNotAuthenticated . mockClear ( ) ;
234+ } ) ;
235+
192236 describe ( 'specifications on Web' , ( ) => {
193237 describe ( 'side effect' , ( ) => {
194238 it ( 'attaches oauth listener to the Amplify singleton' , async ( ) => {
0 commit comments