Comments (15)
Did this ever really make it into the package? I can't find it...
from amplify-ui.
Reopening cc @ericclemmons @sammartinez
from amplify-ui.
This would be particularly handy for those of us not using the UI Components. They already have the onAuthUIStateChange
to work with but many of need to build custom login components.
from amplify-ui.
I'd love to know this too? I can't find any other references.
from amplify-ui.
@Ajit-Singh-Brar So I understand, you'd like a hook or provider for the Auth
category that you can use on its own?
(This sounds related to #254)
The @next
release introduces an Authenticator.Provider
& useAuthenticator()
hook for a truly customized experience (see: #532).
Until then, I've personally used the following useAuth()
hook in my code:
import { Auth, Hub } from 'aws-amplify';
import { useEffect, useState } from 'react';
export default function useAuth() {
const [isLoading, setIsLoading] = useState(true);
const [user, setUser] = useState();
const handleAuth = ({ payload }) => {
switch (payload.event) {
case 'signIn':
return setUser(payload.data);
case 'signOut':
return setUser();
default:
}
};
useEffect(() => {
Auth.currentAuthenticatedUser()
.then(setUser)
.catch(console.error)
.then(() => setIsLoading(false));
Hub.listen('auth', handleAuth);
return () => Hub.remove('auth', handleAuth);
}, []);
return {
Auth,
isLoading,
owner: user ? user.username : null,
user
};
}
It doesn't require a provider, so you would be able to use it like:
function App() {
const { isLoading, user } = useAuth()
if (isLoading) return "Loading..."
if (user) {
return <h1>Welcome {user.username}!</h1>
}
return <MyCustomSignInScreen />
}
from amplify-ui.
This seems like a necessary improvement. Definitely open to reviewing a PR.
I am currently working on an RFC to introduce web components with StencilJS. With this project we would ideally implement a similar design using Stencil's state tunnel. These components could then be used in any framework including the major ones we support.
from amplify-ui.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from amplify-ui.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from amplify-ui.
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.
from amplify-ui.
Bump
from amplify-ui.
@VicStor Thanks a ton for the example implementation for this, using it in my codebase for now.
Why in the world does this still not come with the amplify react library? This should be a no-brainer.
from amplify-ui.
I was following the same template for the Provider pattern for AuthProvider. The following commented line:
useEffect(() => {
Hub.listen('auth', ({ payload }) => {
const { event, data } = payload
if (event === 'signOut') {
setAuth({ state: event, user: null })
localStorage.deleteItem(AUTHENTICATOR_AUTHSTATE)
return
}
localStorage.setItem(AUTHENTICATOR_AUTHSTATE, 'signedIn')
setAuth({ state: event, user: data }) // when this statement gets executed it is causing problem at my forgotPassword component which never shows me the ResetPassword component when the user receives the confirmation code.
})
}, [])
That statement with comment, if it is actually commented then it is affecting the authState. When I am trying to perform the signIn. It gets authenticated but doesn't redirects to the page . Once refreshed it, it shows the actual page, until unless not. How can I solve this issue
from amplify-ui.
Hi @ericclemmons , can you help me with this issue to solve the problem which is happening on the Sign In and ForgotPassword component. If I am commenting the "setAuth" statement, the ForgotPassword works properly, but authentication on Sign IN, afetr signing In doesn't redirects to the actual page after login.
It will be very kind, if you help me out on this
from amplify-ui.
Thanks. It has solved my problem.
from amplify-ui.
That's great to hear! In the meantime, I'll close this as resolved via #532 and we'll get the documentation added for useAuthenticator
as part of #552.
from amplify-ui.
Related Issues (20)
- Session Not Found HOT 15
- Authenticator error message overflows if message is long HOT 2
- Issue with `withAuthenticator` hook integration in Next.js app HOT 3
- Ionic Chatbot UI [missing-page] HOT 2
- Ability to specify auth flow to trigger user migration events HOT 2
- Reset Password by Email not showing correct translations HOT 3
- SelectField SVG accessibility
- Liveness - Your account isn't authorized to call this operation HOT 11
- Pass className prop through to StorageImage HOT 1
- Could not resolve all files for configuration ':amazon-cognito-identity-js:debugCompileClasspath'. HOT 1
- Vite React - Component does not work correctly in mobile browsers, especially Google browsers HOT 8
- Liveness - Users getting timeout error as soon as they try to load HOT 13
- Undefined ('S3Object') Error HOT 12
- Customizable Visual Feedback Colors in Liveness Component HOT 3
- Autocomplete footer not allowing onClick HOT 2
- [Face Liveness] Cannot complete check due to server issue. Try again HOT 13
- Authenticator with only social sign in (hide regular sign in fields) HOT 2
- React: Set unique id to each authenticator step's button HOT 3
- Unrecognizable lambda output - When user Create an account HOT 1
- ResizeObserver loop when navigating in the Authenticator component HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amplify-ui.