···11+---
22+import { SPOTIFY_CLIENT_ID, SPOTIFY_REDIRECT_URI } from "astro:env/server";
33+import { getAccessCode } from "/components/playing/spotify";
44+// make a 404 if accidentally left in prod
55+if (import.meta.env.PROD) return Astro.redirect("/404", 404);
66+77+const userAuthCode = Astro.url.searchParams.get("code") ?? undefined;
88+99+const userAccessToken = await getAccessCode(userAuthCode).catch((err) => err);
1010+1111+const href = `https://accounts.spotify.com/authorize?response_type=code&client_id=${SPOTIFY_CLIENT_ID}&scope=user-read-currently-playing&redirect_uri=${SPOTIFY_REDIRECT_URI}`;
1212+---
1313+1414+<p>
1515+ This endpoint is avaliable at /callback when the _ is removed from the start
1616+ of the filename.
1717+</p>
1818+1919+<p>This endpoint is to gain the first access token and refresh token.</p>
2020+2121+<p>
2222+ Opening the endpoint with no query parameters will provide a link to authorize
2323+ the configured application
2424+</p>
2525+2626+<p>
2727+ This should redirect back here where it gains an access token and shows a
2828+ sucess method
2929+</p>
3030+3131+<p>The refresh token is automatically stored for later requests.</p>
3232+3333+<p>
3434+ <a {href}>Get Authorized</a>
3535+</p>
3636+3737+<p>
3838+ {
3939+ userAuthCode &&
4040+ (userAccessToken ? (
4141+ <>
4242+ Authenticated Successfully!
4343+ <code>{userAccessToken}</code>
4444+ </>
4545+ ) : (
4646+ <>Authentication Failed or was already used</>
4747+ ))
4848+ }
4949+</p>
5050+5151+<style>
5252+ p,
5353+ code {
5454+ max-width: 40ch;
5555+ }
5656+5757+ code {
5858+ word-wrap: break-word;
5959+ }
6060+</style>