<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> <script> const { Client, Account, OAuthProvider } = Appwrite; // Import all const client = new Client(); const projectID = 'YOUR_PROJECT_ID'; // Replace with your actual project ID client .setEndpoint('https://cloud.appwrite.io/v1') .setProject(projectID); const account = new Account(client); // Configure Google OAuth2 provider (assuming you have configured it in Appwrite) const provider = OAuthProvider.Google; // Use OAuthProvider.Google for Google OAuth2 // Example: Initiate Google OAuth2 login account.createOAuth2Session(provider, 'https://your-website.com/callback', 'https://your-website.com/error') // Replace URLs with yours .then(response => { console.log("OAuth2 session created:", response); // Handle successful session creation (e.g., redirect user) }) .catch(error => { console.error("OAuth2 session creation failed:", error); // Handle errors during OAuth2 login (e.g., display error message) }); </script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> <script> const { Client, Account } = Appwrite; // Import necessary parts const client = new Client(); const projectID = 'YOUR_PROJECT_ID'; // Replace with your actual project ID client .setEndpoint('https://cloud.appwrite.io/v1') .setProject(projectID); const account = new Account(client); let refreshTokenAttempted = false; // Flag to track refresh attempt // Retrieve current session information account.getSession('current') .then(session => { console.log("Session information:"); console.log(" Provider:", session.provider); console.log(" Provider UID:", session.providerUid); console.log(" Provider Access Token:", session.providerAccessToken); // Store session data in local storage (optional) localStorage.setItem('sessionData', JSON.stringify(session)); // Retrieve user profile (optional) return account.getAccount(session.userId); }) .then(userProfile => { console.log("User profile:", userProfile); // Access user data }) .catch(error => { console.error("Error:", error); // Handle errors during session retrieval or profile retrieval }); // Optional: Check for session expiration (assuming no built-in event) setInterval(() => { // Check if session is still valid (implementation might vary) // ... (e.g., call an Appwrite API endpoint requiring authentication) if (!refreshTokenAttempted) { console.log("Session might be expired. Attempting refresh..."); refreshTokenAttempted = true; // Prevent multiple refresh attempts // Redirect user to login page for refresh window.location.href = "'https://your-website.com/login"; } }, 5000); // Check every 5 seconds (adjust as needed) </script>
? i can put on the page itself like in webflow? ig no? so i believe i can just use a html embed with this , on the very top ig? after the body ? ( ref 2nd image) so when the page loads. it loads this html embed first then the rest of the stuff right? as per as how the body structure is? is it how it works within webstudio?","dateCreated":"2024-06-18T20:22:02.575Z","dateModified":"2024-06-18T20:22:02.575Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":18,"upvoteCount":0},{"@type":"Comment","text":"@JoqniX︲🎋🌟🌠 , if there's a scrip that you need across on your entire site (example: analytics) you can add it to the project settings. There's a place for there.What that snippet is saying is that you can call that CDN script on your page, but if you need to call the functions within it, then you'll need to include that scripting after this CDN link.","dateCreated":"2024-06-19T04:44:06.312Z","dateModified":"2024-06-19T04:44:06.312Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/6c66325d-fff8-43a2-b97e-549275813461","name":"Jeremy","identifier":"6c66325d-fff8-43a2-b97e-549275813461","image":"https://cdn.discordapp.com/avatars/383871071566430208/6de448190b31c7a9af49e5fbd4f5d047.webp?size=256"},"commentCount":0,"comment":[],"position":19,"upvoteCount":0},{"@type":"Comment","text":"oh! thank you!","dateCreated":"2024-06-19T05:34:46.052Z","dateModified":"2024-06-19T05:34:46.052Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":20,"upvoteCount":0},{"@type":"Comment","text":"oh boy! im happy to say that. ever since yesterday till till now. me was at it for a while hours. ( while watching some videos and testing other services except appwrite etc) and it finally worked! followed this - gemini saved me! \n","dateCreated":"2024-06-19T16:57:30.421Z","dateModified":"2024-06-19T16:57:30.421Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":21,"upvoteCount":0},{"@type":"Comment","text":"Nice work!","dateCreated":"2024-06-19T16:59:24.528Z","dateModified":"2024-06-19T16:59:24.528Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/6c66325d-fff8-43a2-b97e-549275813461","name":"Jeremy","identifier":"6c66325d-fff8-43a2-b97e-549275813461","image":"https://cdn.discordapp.com/avatars/383871071566430208/6de448190b31c7a9af49e5fbd4f5d047.webp?size=256"},"commentCount":0,"comment":[],"position":22,"upvoteCount":0},{"@type":"Comment","text":"as i was watching this video where they used xano. i had made 2 pages - one for login , and other for myaccountso currently this code is in the login page. as a html embed, so it instantly directs me to the google oauth page as seen in the screenshot. so now i needa figure out how i can make so that. when i press login button. on my page. it then redirects to the google oauth.","dateCreated":"2024-06-19T16:59:42.950Z","dateModified":"2024-06-19T16:59:42.950Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":23,"upvoteCount":0},{"@type":"Comment","text":"and the other thing i noticed is -. since i have made a myaccount page . i kept that as my callback url.i used this code so it somehow catches it and logs to local storage and stuff? if it needs to be refreshed, then it redirects back to the login page.but it seems to be not working ;w; idk . i see the request was redirected error idk why? here's the code gemini gave me!\n","dateCreated":"2024-06-19T17:03:24.448Z","dateModified":"2024-06-19T17:03:24.448Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":24,"upvoteCount":0},{"@type":"Comment","text":"so yea currently stuck at this. but atleast the google oauth page showed up! im happy 😭 dunno why the app name was - appwrite.io , tho i gave a different name in google cloud for the oauth 2.0 client","dateCreated":"2024-06-19T17:05:49.112Z","dateModified":"2024-06-19T17:05:49.112Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":25,"upvoteCount":0},{"@type":"Comment","text":"do let me know if i needa share my build or something. or provide link to the site etc.","dateCreated":"2024-06-19T17:07:59.916Z","dateModified":"2024-06-19T17:07:59.916Z","author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"commentCount":0,"comment":[],"position":26,"upvoteCount":0}],"author":{"@type":"Person","url":"https://help.webstudio.is/members/c17e958d-1aa9-4011-b8a2-b710e1a4637d","name":"JoqniX︲🎋🌟🌠","identifier":"c17e958d-1aa9-4011-b8a2-b710e1a4637d","image":"https://cdn.discordapp.com/avatars/334343489288404993/855c2b89c85190416d7abc7af2c7b274.webp?size=256"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}}]