This commit is contained in:
Jozef Steinhübl 2024-07-16 17:32:46 +00:00 committed by GitHub
commit b3073a9aa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 80 additions and 34 deletions

View file

@ -2,36 +2,24 @@ import path from "path";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
import { defineConfig } from "astro/config"; import { defineConfig } from "astro/config";
import sitemap from "@astrojs/sitemap"; import sitemap from "@astrojs/sitemap";
import robotsTxt from "astro-robots-txt";
import compress from "astro-compress";
import tailwind from "@astrojs/tailwind"; import tailwind from "@astrojs/tailwind";
import cloudflare from "@astrojs/cloudflare";
import auth from "auth-astro";
import { CONFIG } from "./src/config"; import { CONFIG } from "./src/config";
import image from "@astrojs/image";
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
site: CONFIG.origin, site: CONFIG.origin,
base: "/", integrations: [sitemap(), tailwind(), auth()],
trailingSlash: "always", output: "server",
output: "static", adapter: cloudflare(),
integrations: [sitemap(), robotsTxt({ vite: {
policy: [{ resolve: {
userAgent: "*" alias: {
}], "~": path.resolve(__dirname, "./src"),
sitemap: true },
}), compress({ },
css: true, },
html: true, });
img: true,
js: true,
svg: true
}), tailwind(), image()],
vite: {
resolve: {
alias: {
"~": path.resolve(__dirname, "./src")
}
}
}
});

View file

@ -0,0 +1,23 @@
import Discord from "@auth/core/providers/discord";
import { defineConfig } from "auth-astro";
export default defineConfig({
providers: [
Discord({
clientId: import.meta.env.DISCORD_CLIENT_ID,
clientSecret: import.meta.env.DISCORD_CLIENT_SECRET,
}),
],
callbacks: {
session({ session, token }) {
if (session.user && token?.sub) {
session.user.id = token.sub;
}
return session;
},
},
pages: {
signIn: "/auth/login",
signOut: "/auth/logout",
},
});

BIN
apps/website/bun.lockb Executable file

Binary file not shown.

View file

@ -9,16 +9,16 @@
"astro": "astro" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/image": "^0.16.5", "@astrojs/cloudflare": "^11.0.1",
"@astrojs/prefetch": "^0.2.1", "@astrojs/prefetch": "^0.2.1",
"@astrojs/sitemap": "^1.2.1", "@astrojs/sitemap": "^3.1.6",
"@astrojs/tailwind": "^3.1.1", "@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.32.0",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"astro": "^2.2.1", "astro": "^4.11.5",
"astro-compress": "2.2.11",
"astro-google-fonts-optimizer": "^0.2.2", "astro-google-fonts-optimizer": "^0.2.2",
"astro-icon": "^0.8.0", "astro-icon": "^0.8.0",
"astro-robots-txt": "^0.4.1", "auth-astro": "^4.1.2",
"tailwindcss": "^3.3.1" "tailwindcss": "^3.3.1"
}, },
"devDependencies": { "devDependencies": {

View file

@ -0,0 +1,13 @@
---
import Layout from "~/layouts/Layout.astro";
---
<Layout>
<script>
const { signIn } = await import("auth-astro/client");
signIn("discord", {
redirect: false,
callbackUrl: "/dashboard",
});
</script>
</Layout>

View file

@ -0,0 +1,14 @@
---
import Layout from "~/layouts/Layout.astro";
---
<Layout>
<script>
const { signOut } = await import("auth-astro/client");
signOut({
// @ts-expect-error
redirect: false,
callbackUrl: "/",
});
</script>
</Layout>

View file

@ -0,0 +1,8 @@
---
import { getSession } from "auth-astro/server";
const session = await getSession(Astro.request);
console.log(session);
---
{session ? <p>Welcome {session.user?.name}</p> : <p>Not logged in</p>}

View file

@ -2,8 +2,8 @@
import Layout from "~/layouts/Layout.astro"; import Layout from "~/layouts/Layout.astro";
import Invite from "~/components/Invite.astro"; import Invite from "~/components/Invite.astro";
import Computer from "~/components/Computer.astro"; import Computer from "~/components/Computer.astro";
import { Image } from "@astrojs/image/components";
import Logo from "~/assets/logo.png"; import Logo from "~/assets/logo.png";
import { Image } from "astro:assets";
--- ---
<Layout> <Layout>