-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add Auth to React context using Provider pattern #551
Comments
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. |
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. |
1 similar comment
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. |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
Did this ever really make it into the package? I can't find it... |
I'd love to know this too? I can't find any other references. |
Bump |
@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. |
Reopening cc @ericclemmons @sammartinez |
This would be particularly handy for those of us not using the UI Components. They already have the |
I was following the same template for the Provider pattern for AuthProvider. The following commented line:
|
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 |
@Ajit-Singh-Brar So I understand, you'd like a hook or provider for the (This sounds related to #254) The Until then, I've personally used the following 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 />
} |
Thanks. It has solved my problem. |
…client chore: update client-rekognitionstreaming to turn on frame signing
Is your feature request related to a problem? Please describe.
A pattern used for Authenticator (withAuthenticator) React component is hardly extensible.
Prev feature request
Describe the solution you'd like
Use Provider pattern to track authentication state.
Describe alternatives you've considered
Here is very basic implementation
Wrap app in AuthProvider
Use
auth
context where you need itAdditional context
Let me know you not mind to add this. I could implement it quite easily.
The text was updated successfully, but these errors were encountered: