Skip to content

Commit

Permalink
Merge pull request #3 from corbado/2-fix-issues
Browse files Browse the repository at this point in the history
fix the issue with the logout & refactor the code
  • Loading branch information
vincentdelitz authored Aug 13, 2024
2 parents 8a8896a + 909374b commit 82d5dbc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Please see the full [blog post](https://www.corbado.com/blog/astro-passkeys) to
- `src/components/PasskeyList.astro`: Component for displaying the list of passkeys.
- `src/pages/Login.astro`: Page component for the sign-up / login screen.
- `src/pages/Profile.astro`: Page component for the user profile information shown after successful authentication.
- `corbadoSetup.js`: JavaScript file that contains the shared logic for initializing Corbado.

## Setup

Expand Down
6 changes: 0 additions & 6 deletions corbadoSetup.js

This file was deleted.

12 changes: 10 additions & 2 deletions src/components/PasskeyList.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
---
const projectId = import.meta.env.PUBLIC_CORBADO_PROJECT_ID;
---

<div id="passkey-list"></div>
<script type="module">
import { loadCorbadoProject } from "./corbadoSetup.js";
<script type="module" define:vars={{ projectId }}>
const loadCorbadoProject = async () => {
await Corbado.load({
projectId: projectId,
});
};

const initializePasskeyList = async () => {
await loadCorbadoProject();
Expand Down
10 changes: 7 additions & 3 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
const projectId = import.meta.env.PUBLIC_CORBADO_PROJECT_ID;
---

<html>
Expand Down Expand Up @@ -37,8 +37,12 @@
<div class="container">
<div id="corbado-auth"></div>
</div>
<script type="module">
import { loadCorbadoProject } from "./corbadoSetup.js";
<script type="module" define:vars={{ projectId }}>
const loadCorbadoProject = async () => {
await Corbado.load({
projectId: projectId,
});
};

const initializeCorbado = async () => {
await loadCorbadoProject();
Expand Down
13 changes: 9 additions & 4 deletions src/pages/profile.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import PasskeyList from "../components/PasskeyList.astro";
const projectId = import.meta.env.PUBLIC_CORBADO_PROJECT_ID;
---

<html>
Expand Down Expand Up @@ -40,8 +41,12 @@ import PasskeyList from "../components/PasskeyList.astro";
<PasskeyList />
<button id="logout-button" style="display: none;">Logout</button>
</div>
<script type="module">
import { loadCorbadoProject } from "./corbadoSetup.js";
<script type="module" define:vars={{ projectId }}>
const loadCorbadoProject = async () => {
await Corbado.load({
projectId: projectId,
});
};

const initializeProfile = async () => {
await loadCorbadoProject();
Expand All @@ -55,11 +60,11 @@ import PasskeyList from "../components/PasskeyList.astro";
logoutButton.style.display = "block";
logoutButton.addEventListener("click", () => {
Corbado.logout();
window.location.href = "/login";
window.location.href = "/#login-init";
});
} else {
profileContent.innerHTML =
'<p>Please <a href="/login">login</a> to view your profile.</p>';
'<p>Please <a href="/#login-init">login</a> to view your profile.</p>';
}
};

Expand Down

0 comments on commit 82d5dbc

Please sign in to comment.