fast-lunch-54279
chilly-king-10285
11/07/2023, 2:43 PMchilly-king-10285
11/07/2023, 2:44 PMhtml <!DOCTYPE html> <html> <head> <title>Login with Google</title> <script src="https://unpkg.com/@ory/client"></script> </head> <body> <button id="login">Sign in with Google</button> <script> const frontend = new FrontendApi( new Configuration({ basePath: "<http://localhost:4000>", // Use your local Ory Tunnel URL baseOptions: { withCredentials: true, // we need to include cookies }, }) ); document.getElementById('login').addEventListener('click', function() { frontend .createBrowserLoginFlow({ returnTo: "/", // redirect to the root path after login refresh: true, }) .then(({ data: flow }) => { // Redirect to Google sign-in window.location.href = flow.action; }) .catch((err) => { // Couldn't create login flow // handle the error console.error(err); }); }); </script> </body> </html>
This script uses the Ory SDK (@ory/client
) to create a login flow when the user clicks the "Sign in with Google" button. After the login flow is created, the user is redirected to the Google sign-in page. Please note that this is a simplified example and does not include error handling or other considerations for a production environment. You may need to adjust the code to fit your specific needs and environment. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration).