mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-11-10 03:08:06 +01:00
feat(website): add auth-astro & basic routes
This commit is contained in:
parent
791a779715
commit
303c1c881e
8 changed files with 80 additions and 34 deletions
|
@ -2,36 +2,24 @@ import path from "path";
|
|||
import { fileURLToPath } from "url";
|
||||
import { defineConfig } from "astro/config";
|
||||
import sitemap from "@astrojs/sitemap";
|
||||
import robotsTxt from "astro-robots-txt";
|
||||
import compress from "astro-compress";
|
||||
import tailwind from "@astrojs/tailwind";
|
||||
import cloudflare from "@astrojs/cloudflare";
|
||||
import auth from "auth-astro";
|
||||
import { CONFIG } from "./src/config";
|
||||
import image from "@astrojs/image";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
site: CONFIG.origin,
|
||||
base: "/",
|
||||
trailingSlash: "always",
|
||||
output: "static",
|
||||
integrations: [sitemap(), robotsTxt({
|
||||
policy: [{
|
||||
userAgent: "*"
|
||||
}],
|
||||
sitemap: true
|
||||
}), compress({
|
||||
css: true,
|
||||
html: true,
|
||||
img: true,
|
||||
js: true,
|
||||
svg: true
|
||||
}), tailwind(), image()],
|
||||
integrations: [sitemap(), tailwind(), auth()],
|
||||
output: "server",
|
||||
adapter: cloudflare(),
|
||||
vite: {
|
||||
resolve: {
|
||||
alias: {
|
||||
"~": path.resolve(__dirname, "./src")
|
||||
}
|
||||
}
|
||||
}
|
||||
"~": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
23
apps/website/auth.config.ts
Normal file
23
apps/website/auth.config.ts
Normal 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
BIN
apps/website/bun.lockb
Executable file
Binary file not shown.
|
@ -9,16 +9,16 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/image": "^0.16.5",
|
||||
"@astrojs/cloudflare": "^11.0.1",
|
||||
"@astrojs/prefetch": "^0.2.1",
|
||||
"@astrojs/sitemap": "^1.2.1",
|
||||
"@astrojs/tailwind": "^3.1.1",
|
||||
"@astrojs/sitemap": "^3.1.6",
|
||||
"@astrojs/tailwind": "^5.1.0",
|
||||
"@auth/core": "^0.18.6",
|
||||
"@tailwindcss/typography": "^0.5.9",
|
||||
"astro": "^2.2.1",
|
||||
"astro-compress": "2.2.11",
|
||||
"astro": "^4.11.5",
|
||||
"astro-google-fonts-optimizer": "^0.2.2",
|
||||
"astro-icon": "^0.8.0",
|
||||
"astro-robots-txt": "^0.4.1",
|
||||
"auth-astro": "^4.1.2",
|
||||
"tailwindcss": "^3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
13
apps/website/src/pages/auth/login.astro
Normal file
13
apps/website/src/pages/auth/login.astro
Normal 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>
|
14
apps/website/src/pages/auth/logout.astro
Normal file
14
apps/website/src/pages/auth/logout.astro
Normal 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>
|
8
apps/website/src/pages/dashboard/index.astro
Normal file
8
apps/website/src/pages/dashboard/index.astro
Normal 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>}
|
|
@ -2,8 +2,8 @@
|
|||
import Layout from "~/layouts/Layout.astro";
|
||||
import Invite from "~/components/Invite.astro";
|
||||
import Computer from "~/components/Computer.astro";
|
||||
import { Image } from "@astrojs/image/components";
|
||||
import Logo from "~/assets/logo.png";
|
||||
import { Image } from "astro:assets";
|
||||
---
|
||||
|
||||
<Layout>
|
||||
|
|
Loading…
Reference in a new issue