Fix: Add testing
This commit is contained in:
parent
d022d9fcf6
commit
ed6195e1e2
22 changed files with 338 additions and 87 deletions
|
@ -4,6 +4,12 @@ import "../styles/components/NavBar.scss";
|
|||
import { FontAwesomeIcon } from "./FontAwesomeIcon";
|
||||
import NavUser from "./NavUser";
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_CLIENT_ID === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_CLIENT_ID found!");
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_OAUTH2_PERMISSIONS === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_OAUTH2_PERMISSIONS found!");
|
||||
|
||||
export function Li(props: {
|
||||
href: string;
|
||||
rel?: string;
|
||||
|
@ -36,7 +42,7 @@ function NavBar() {
|
|||
</ul>
|
||||
<ul class="flex-row responsive thick">
|
||||
<Li
|
||||
href={`https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot`}
|
||||
href={`https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_OAUTH2_PERMISSIONS}&scope=bot`}
|
||||
name="Invite to your server"
|
||||
>
|
||||
<FontAwesomeIcon class="lower" icon={faCirclePlus} size="xl" />
|
||||
|
|
|
@ -2,7 +2,10 @@ import { drizzle } from "drizzle-orm/postgres-js";
|
|||
import postgres from "postgres";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const queryClient = postgres(import.meta.env.VITE_DATABASE_URL ?? "");
|
||||
if (typeof import.meta.env.VITE_DATABASE_URL === "undefined")
|
||||
throw new Error("No env VITE_DATABASE_URL found!");
|
||||
|
||||
const queryClient = postgres(import.meta.env.VITE_DATABASE_URL);
|
||||
const db = drizzle(queryClient, {
|
||||
schema,
|
||||
});
|
||||
|
|
|
@ -4,6 +4,18 @@ import { Lucia } from "lucia";
|
|||
import db from "~/drizzle";
|
||||
import { sessions, users } from "~/drizzle/schema";
|
||||
|
||||
if (typeof import.meta.env.PROD === "undefined")
|
||||
throw new Error("No env PROD found!");
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_CLIENT_ID === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_CLIENT_ID found!");
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_CLIENT_SECRET === "undefined")
|
||||
throw new Error("No env PROD found!");
|
||||
|
||||
if (typeof import.meta.env.VITE_AUTH_REDIRECT_URL === "undefined")
|
||||
throw new Error("No env VITE_AUTH_REDIRECT_URL found!");
|
||||
|
||||
const adapter = new DrizzlePostgreSQLAdapter(db, sessions, users);
|
||||
|
||||
export const lucia = new Lucia(adapter, {
|
||||
|
|
|
@ -11,12 +11,11 @@ import { discord, lucia } from "~/lib/auth";
|
|||
import { paths } from "~/types/discord";
|
||||
|
||||
export async function GET(event: APIEvent): Promise<Response> {
|
||||
const code = new URL(event.request.url).searchParams.get("code");
|
||||
const state = new URL(event.request.url).searchParams.get("state");
|
||||
const error = new URL(event.request.url).searchParams.get("error");
|
||||
const error_description = new URL(event.request.url).searchParams.get(
|
||||
"error_description",
|
||||
);
|
||||
const url = new URL(event.request.url);
|
||||
const code = url.searchParams.get("code");
|
||||
const state = url.searchParams.get("state");
|
||||
const error = url.searchParams.get("error");
|
||||
const error_description = url.searchParams.get("error_description");
|
||||
if (error)
|
||||
switch (error) {
|
||||
case "access_denied":
|
||||
|
@ -61,7 +60,6 @@ export async function GET(event: APIEvent): Promise<Response> {
|
|||
{ sessionId: createId() },
|
||||
);
|
||||
const sessionCookie = lucia.createSessionCookie(session.id);
|
||||
console.log(sessionCookie);
|
||||
setCookie(
|
||||
sessionCookie.name,
|
||||
sessionCookie.value,
|
||||
|
@ -100,7 +98,6 @@ export async function GET(event: APIEvent): Promise<Response> {
|
|||
})
|
||||
.returning()
|
||||
.execute();
|
||||
console.log(createId(), createId(), { warst: createId() });
|
||||
const session = await lucia.createSession(
|
||||
userId,
|
||||
{},
|
||||
|
|
|
@ -4,6 +4,9 @@ import httpStatus from "http-status";
|
|||
import { setCookie } from "vinxi/http";
|
||||
import { discord } from "~/lib/auth";
|
||||
|
||||
if (typeof import.meta.env.PROD === "undefined")
|
||||
throw new Error("No env PROD found!");
|
||||
|
||||
export async function GET(event: APIEvent) {
|
||||
const state = generateState();
|
||||
const url = await discord.createAuthorizationURL(state, {
|
||||
|
|
|
@ -19,6 +19,9 @@ import { discordTokens } from "~/drizzle/schema";
|
|||
import { paths } from "~/types/discord";
|
||||
import "../../styles/pages/config.scss";
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_BOT_TOKEN === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_BOT_TOKEN found!");
|
||||
|
||||
const guessTZ = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
const initialValue = (params: ReturnType<typeof useParams>) => ({
|
||||
|
|
|
@ -15,6 +15,12 @@ import { discordTokens } from "~/drizzle/schema";
|
|||
import { paths } from "~/types/discord";
|
||||
import "../../styles/pages/config.scss";
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_CLIENT_ID === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_CLIENT_ID found!");
|
||||
|
||||
if (typeof import.meta.env.VITE_DISCORD_OAUTH2_PERMISSIONS === "undefined")
|
||||
throw new Error("No env VITE_DISCORD_OAUTH2_PERMISSIONS found!");
|
||||
|
||||
const initialValue = () => ({
|
||||
success: null as boolean | null,
|
||||
guilds: [] as {
|
||||
|
@ -105,7 +111,7 @@ function index() {
|
|||
href={
|
||||
i() % 3 === 0
|
||||
? `/config/${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_OAUTH2_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
}
|
||||
class="flex-row centered"
|
||||
>
|
||||
|
|
2
src/types/env.d.ts
vendored
2
src/types/env.d.ts
vendored
|
@ -4,7 +4,7 @@ interface ImportMetaEnv {
|
|||
readonly VITE_DISCORD_CLIENT_ID: string;
|
||||
readonly VITE_DISCORD_CLIENT_SECRET: string;
|
||||
readonly VITE_DISCORD_BOT_TOKEN: string;
|
||||
readonly VITE_DISCORD_BOT_PERMISSIONS: string;
|
||||
readonly VITE_DISCORD_OAUTH2_PERMISSIONS: string;
|
||||
|
||||
readonly VITE_AUTH_SECRET: string;
|
||||
readonly VITE_AUTH_REDIRECT_PROXY_URL: string | undefined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue