Web Developers : 16-Checking Login Status on a New Tab with Appwrite Authentication - SkillBakery Studios

Breaking

Post Top Ad

Post Top Ad

Saturday, July 18, 2026

Web Developers : 16-Checking Login Status on a New Tab with Appwrite Authentication

Web Developers : 16-Checking Login Status on a New Tab with Appwrite Authentication

Screenshot from the tutorial
Screenshot from the tutorial

Checking Login Status on a New Tab with Appwrite Authentication

In the world of web development, managing user authentication effectively is paramount to creating a secure and user-friendly experience. This tutorial will guide you through the process of checking login status on a new tab using Appwrite, a powerful backend as a service (BaaS) that simplifies backend functionalities like user authentication.

What You Will Learn

In this tutorial, you will learn how to:

  1. Set up Appwrite for authentication.
  2. Check user login status on a new tab.
  3. Handle user redirection based on authentication status.

Prerequisites

Before diving into the tutorial, ensure you have the following:

  • A basic understanding of JavaScript and web development concepts.
  • An Appwrite server set up and running.
  • Familiarity with HTML and CSS for creating a simple web interface.

Setting Up Appwrite

If you haven't set up Appwrite yet, follow these steps:

  1. Install Appwrite: You can run Appwrite using Docker. Use the following command:

    docker run -d --restart always --network host appwrite/appwrite
    
  2. Create a Project: After setting up, log in to the Appwrite console and create a new project.

  3. Enable Authentication: Navigate to the ‘Authentication’ section and enable the providers you wish to use (e.g., email/password).

  4. Create a Web Client: Obtain your project’s API endpoint and project ID from the Appwrite console.

Checking Login Status on a New Tab

Now that you have Appwrite set up, let's move on to checking the login status in a new tab.

Step 1: Set Up the HTML Structure

Create a simple HTML file (index.html) to serve as your starting point. Below is a basic structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appwrite Authentication</title>
    <script src="https://cdn.jsdelivr.net/npm/appwrite"></script>
</head>
<body>
    <h1>Check Login Status</h1>
    <button id="newTabBtn">Open New Tab</button>
    <script src="app.js"></script>
</body>
</html>

Step 2: Implementing the JavaScript Logic

Next, create a JavaScript file (app.js) to manage the authentication logic. Here’s how to check the login status on a new tab:

const client = new Appwrite.Client();
const account = new Appwrite.Account(client);

// Configure the Appwrite client
client
    .setEndpoint('YOUR_APPWRITE_ENDPOINT') // Your API endpoint
    .setProject('YOUR_PROJECT_ID'); // Your project ID

// Function to check login status
async function checkLoginStatus() {
    try {
        const user = await account.get();
        return user;
    } catch (error) {
        console.error('User is not logged in:', error);
        return null;
    }
}

// Open new tab and check login status
document.getElementById('newTabBtn').addEventListener('click', async () => {
    const user = await checkLoginStatus();
    const newTab = window.open('newTab.html', '_blank');

    // Pass login status via localStorage or query parameters
    if (user) {
        newTab.localStorage.setItem('user', JSON.stringify(user));
    } else {
        newTab.localStorage.setItem('user', null);
    }
});

Step 3: Handling Login Status in New Tab

Create another HTML file (newTab.html) to handle the user login status in the new tab:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>New Tab</title>
</head>
<body>
    <h1>New Tab Status</h1>
    <div id="status"></div>
    <script>
        const userStatus = JSON.parse(localStorage.getItem('user'));
        document.getElementById('status').innerText = userStatus 
            ? `Logged in as: ${userStatus.name}` 
            : 'User is not logged in.';
    </script>
</body>
</html>

Conclusion

In this tutorial, we have covered how to check the login status using Appwrite authentication and handle it across multiple tabs. By leveraging Appwrite's client library, we can efficiently manage user sessions and improve the overall user experience.

Next Steps

  • Explore more Appwrite functionalities such as database management, file storage, and real-time capabilities.
  • Consider implementing token-based authentication for enhanced security.
  • Experiment with different front-end frameworks like React or Vue.js to build more dynamic applications.

Happy coding! If you have any questions or feedback, feel free to leave a comment below.

Another screenshot from the tutorial
Another view from the tutorial

Connect with SkillBakery Studios

Explore more tutorials, tools, and resources:

Posted by SkillBakery Studios

No comments:

Post a Comment

Post Top Ad