-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(examples,e2e): Add examples and tests for #1580 #1578
Changes from 16 commits
6925d4e
9f48b32
d4f0742
126314b
7aee0cf
81492e1
a6e26ea
5a090b8
d080bc2
abeeb47
3e3527f
4ab0271
b3e5a90
bde17ec
5a62d1d
c9cf401
bae13aa
18e55d5
16aefaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div>Hello, {{ authenticator.user?.username }}!</div> | ||
<button (click)="handleClick($event)">Sign Out</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component } from '@angular/core'; | ||
import { Router, ActivatedRoute } from '@angular/router'; | ||
import { Amplify } from 'aws-amplify'; | ||
import { AuthenticatorService } from '@aws-amplify/ui-angular'; | ||
|
||
import awsExports from '../aws-exports'; | ||
|
||
@Component({ | ||
selector: 'use-authenticator', | ||
templateUrl: 'useAuthenticatorHome.component.html', | ||
}) | ||
export class UseAuthenticatorHomeComponent { | ||
constructor( | ||
public authenticator: AuthenticatorService, | ||
private router: Router, | ||
private route: ActivatedRoute | ||
) { | ||
Amplify.configure(awsExports); | ||
} | ||
|
||
public handleClick(event: Event) { | ||
event.preventDefault(); | ||
this.authenticator.signOut(); | ||
this.router.navigate(['../'], { relativeTo: this.route }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
<ng-container *ngIf="authenticator.route === 'authenticated'"> | ||
<h2>Welcome, {{ authenticator.user.username }}!</h2> | ||
<button (click)="authenticator.signOut()">Sign Out</button> | ||
</ng-container> | ||
|
||
<ng-container *ngIf="authenticator.route !== 'authenticated'"> | ||
<amplify-authenticator></amplify-authenticator> | ||
</ng-container> | ||
<amplify-authenticator> | ||
<ng-template amplifySlot="authenticated"> | ||
<button (click)="navigateHome($event)">Navigate to Home</button> | ||
</ng-template> | ||
</amplify-authenticator> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { Component } from '@angular/core'; | ||
import { Amplify } from 'aws-amplify'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Amplify, Auth } from 'aws-amplify'; | ||
import { AuthenticatorService } from '@aws-amplify/ui-angular'; | ||
|
||
import awsExports from './aws-exports'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'use-authenticator', | ||
templateUrl: 'useAuthenticator.component.html', | ||
}) | ||
export class UseAuthenticatorComponent { | ||
constructor(public authenticator: AuthenticatorService) { | ||
constructor( | ||
public authenticator: AuthenticatorService, | ||
private router: Router, | ||
private route: ActivatedRoute | ||
) { | ||
Amplify.configure(awsExports); | ||
} | ||
|
||
public navigateHome(event: Event) { | ||
event.preventDefault(); | ||
this.router.navigate(['home'], { relativeTo: this.route }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,18 @@ | |
// https://nextjs.org/docs/advanced-features/custom-app | ||
import App from 'next/app'; | ||
import { Amplify } from 'aws-amplify'; | ||
import { Authenticator, AmplifyProvider } from '@aws-amplify/ui-react'; | ||
|
||
if (typeof window !== 'undefined') { | ||
window['Amplify'] = Amplify; | ||
} | ||
|
||
export default App; | ||
export default function MyApp(props) { | ||
return ( | ||
<AmplifyProvider> | ||
<Authenticator.Provider> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was testing this in the other PR and I had to add this. Glad it's there now. |
||
<App {...props} /> | ||
</Authenticator.Provider> | ||
</AmplifyProvider> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Amplify } from 'aws-amplify'; | ||
import { useAuthenticator } from '@aws-amplify/ui-react'; | ||
import * as React from 'react'; | ||
import awsExports from '../aws-exports'; | ||
import router from 'next/router'; | ||
|
||
Amplify.configure(awsExports); | ||
|
||
export default function App() { | ||
const { user, signOut } = useAuthenticator(); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
event.preventDefault(); | ||
signOut(); | ||
router.push('../useAuthenticator'); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div>Hello, {user?.username}!</div> | ||
<button onClick={handleClick}>Sign Out</button> | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,19 @@ | ||
import { Amplify } from 'aws-amplify'; | ||
import router from 'next/router'; | ||
|
||
import { Authenticator, useAuthenticator } from '@aws-amplify/ui-react'; | ||
import { Amplify } from 'aws-amplify'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
|
||
import awsExports from './aws-exports'; | ||
import { Authenticator } from '@aws-amplify/ui-react'; | ||
|
||
Amplify.configure(awsExports); | ||
|
||
const Home = () => { | ||
const { user, signOut } = useAuthenticator((context) => [context.user]); | ||
|
||
return ( | ||
<> | ||
<h2>Welcome, {user.username}!</h2> | ||
<button onClick={signOut}>Sign Out</button> | ||
</> | ||
); | ||
}; | ||
|
||
const Login = () => <Authenticator />; | ||
|
||
function App() { | ||
const { route } = useAuthenticator((context) => [context.route]); | ||
return route === 'authenticated' ? <Home /> : <Login />; | ||
} | ||
export default function App() { | ||
const navigateHome = () => router.push('useAuthenticator/home'); | ||
|
||
export default function AppWithProvider() { | ||
return ( | ||
<Authenticator.Provider> | ||
<App></App> | ||
</Authenticator.Provider> | ||
<Authenticator> | ||
{() => <button onClick={navigateHome}>Navigate to Home</button>} | ||
</Authenticator> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { toRefs } from 'vue'; | ||
import { useRouter } from 'vue-router'; | ||
|
||
import { Amplify } from 'aws-amplify'; | ||
import { Authenticator, useAuthenticator } from '@aws-amplify/ui-vue'; | ||
import '@aws-amplify/ui-vue/styles.css'; | ||
import aws_exports from '../aws-exports'; | ||
|
||
Amplify.configure(aws_exports); | ||
|
||
const router = useRouter(); | ||
const { user, signOut } = toRefs(useAuthenticator()); | ||
const handleClick = (event: Event) => { | ||
event.preventDefault(); | ||
signOut.value(); | ||
router.push('../useAuthenticator'); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<!-- TODO: this authenticator shouldn't be needed --> | ||
<authenticator></authenticator> | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vue still needed this hidden There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I can look at this in a different PR. Maybe we need to add an initialization via provide/inject somewhere. A user could also hide this with CSS when the user is not logged in, I suppose |
||
<div>Hello, {{ user?.username }}!</div> | ||
<button @click="handleClick">Sign Out</button> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Then, When } from 'cypress-cucumber-preprocessor/steps'; | ||
|
||
Then('I see a valid greetings message', () => { | ||
cy.findByRole('document') | ||
.contains(new RegExp('^Hello, .+!$', 'i')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checks if the message has "Hello, {username}" structure. Kept it generic to not expose the test username 😈 |
||
.should('exist'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!