-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from kcoderhtml/refactor-join
feat: updated join logic to use auth.js and be a nicer experience
- Loading branch information
Showing
4 changed files
with
164 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
import Base from "../../Layouts/Base.astro"; | ||
import { getSession } from "auth-astro/server"; | ||
import { type Session } from "@auth/core/types"; | ||
type ExtendedSession = { | ||
team: string; | ||
teamName: string; | ||
teamImage: string; | ||
user: { | ||
role: string; | ||
}; | ||
}; | ||
const session = (await getSession(Astro.request)) as Session & ExtendedSession; | ||
if (session && session.user.role !== "guest") { | ||
const error = "authorization_error"; | ||
const errorDescription = "You are already signed in to a valid team!"; | ||
const queryParams = new URLSearchParams({ error, errorDescription }); | ||
const redirectUrl = `/error?${queryParams.toString()}`; | ||
return new Response(null, { | ||
status: 302, | ||
headers: new Headers({ | ||
Location: redirectUrl, | ||
}), | ||
}); | ||
} | ||
--- | ||
|
||
<Base title="Join"> | ||
<section> | ||
<p> | ||
Hi! If you got here because you have a join code please enter it in the | ||
form below. Otherwise if you would like to start using MagicSnap for your | ||
team you can join our <u | ||
><a href="https://discord.gg/NGWFZg5Fgn">Discord</a></u | ||
> and ask for an invite and we would be happy to help you get started! | ||
</p> | ||
</section> | ||
<section class="joinCodeForm"> | ||
<input type="text" name="codeInput" placeholder="Enter code here" /> | ||
<a href="/join"><button>Join</button></a> | ||
</section> | ||
</Base> | ||
|
||
<style> | ||
.joinCodeForm { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
.joinCodeForm input { | ||
margin: 1rem; | ||
padding: 0.5rem; | ||
} | ||
.joinCodeForm button { | ||
margin-top: 0; | ||
} | ||
</style> | ||
|
||
<script> | ||
const form = document.querySelector(".joinCodeForm"); | ||
const input = form?.querySelector("input"); | ||
const link = form?.querySelector("a"); | ||
|
||
input?.addEventListener("input", async () => { | ||
const code = input?.value; | ||
if (code) { | ||
link?.setAttribute("href", `/join/${code}`); | ||
} | ||
}); | ||
|
||
input?.addEventListener("keydown", (event) => { | ||
if (event.key === "Enter") { | ||
event.preventDefault(); | ||
const code = input?.value; | ||
if (code) { | ||
window.location.href = `/join/${code}`; | ||
} | ||
} | ||
}); | ||
</script> |