Skip to content

Commit 6e16b75

Browse files
committed
added signups, editred login routes, added complete oauth for discord, just need to add to db and change schemas for authority-like accounts
1 parent 917994c commit 6e16b75

20 files changed

Lines changed: 363 additions & 54 deletions

File tree

apps/website/src/app-special.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
transform: translateY(-50%);
1818
}
1919

20+
.button.button-thin {
21+
border: 3px solid black;
22+
}
23+
2024
.button-border {
2125
border: 1px solid black;
2226
text-align: center;

apps/website/src/app.css

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
:root {
88
--button-padding-x: 0.6rem;
99
--button-padding-y: 0.2rem;
10-
--color-primary: #aaaaaa;
11-
--color-secondary: #ccffcc;
12-
--color-green: oklch(0.723 0.219 149.579);
13-
--color-red: oklch(0.637 0.237 25.331);
10+
--color-discord-background: #36373e;
11+
--color-discord-foreground: #5865f2;
12+
--color-green: #00c950;
13+
--color-primary: #502929;
14+
--color-red: #fb2c36;
15+
--color-secondary: #2eac2e;
1416
--transition-time-short: 0.1s;
1517
--transition-time-medium: 0.25s;
1618
--transition-time-long: 0.5s;
@@ -64,13 +66,13 @@ main {
6466
}
6567

6668
.input {
67-
border: 1px solid black;
69+
border: 1px solid gray;
6870
padding-left: 0.2rem;
6971
padding-right: 0.2rem;
7072
}
7173

7274
.input:focus-within {
73-
border: 3px solid black;
75+
border: 1px solid black;
7476
}
7577

7678
.table tr:hover .remove-button {

apps/website/src/lib/classes/Form.svelte.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export class Form {
66

77
constructor(elements: FormElement[]) {
88
this.elements = elements;
9+
10+
for (const element of this.elements) {
11+
element.form = this;
12+
}
913
}
1014

1115
public Clean() {

apps/website/src/lib/classes/FormElement.svelte.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1+
import type { Form } from './Form.svelte';
2+
13
export class FormElement {
24
public element: HTMLInputElement;
35
public id: string;
4-
validation: () => boolean;
5-
invalidMessage: string;
6+
public form?: Form;
7+
private validation: (form: Form) => { success: true } | { success: false; msg: string };
68

7-
constructor(id: string, validation: () => boolean, invalidMessage: string) {
9+
public constructor(id: string, validation: (form: Form) => { success: true } | { success: false; msg: string }) {
810
this.id = id;
911
this.element = undefined as any as HTMLInputElement; // gets defined during onMount;
1012
this.validation = validation;
11-
this.invalidMessage = invalidMessage;
1213
}
1314

1415
/** Contains a side-effect which sets the input's custom validity message and reports it, if false. */
1516
public Validate(): boolean {
16-
if (this.validation()) {
17+
if (!this.form) {
18+
return false;
19+
}
20+
21+
const result = this.validation(this.form);
22+
if (result.success) {
1723
return true;
1824
} else {
19-
this.element.setCustomValidity(this.invalidMessage);
25+
this.element.setCustomValidity(result.msg);
2026
this.element.reportValidity();
2127
return false;
2228
}

apps/website/src/lib/components/RoutePage.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
route: (typeof ROUTES)['PAGES'][number];
99
title: string;
1010
className?: string;
11+
classNameText?: string;
1112
imageUrl?: string;
13+
thin?: boolean;
1214
};
1315
14-
const { route, title, className, imageUrl }: Props = $props();
16+
const { route, title, className, classNameText, imageUrl, thin = false }: Props = $props();
1517
1618
let style = $state('');
1719
@@ -20,9 +22,9 @@
2022
});
2123
</script>
2224

23-
<Link class={['button flex items-center justify-between gap-2', className]} href={route} {style}>
25+
<Link class={['flex items-center justify-between gap-2', thin ? "button button-thin" : "button", className]} href={route} {style}>
2426
{#if imageUrl}
2527
<img alt="related to the route" class="h-auto w-8" src={imageUrl} />
2628
{/if}
27-
<span class="m-auto">{title}</span>
29+
<span class={['m-auto', classNameText]}>{title}</span>
2830
</Link>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script lang="ts">
2+
import { goto } from '$app/navigation';
3+
import { base } from '$app/paths';
4+
import {
5+
PUBLIC_DISCORD_OAUTH_CLIENT_ID,
6+
PUBLIC_DISCORD_OAUTH_REDIRECT_URI,
7+
PUBLIC_DISCORD_OAUTH_REDIRECT_URI_TEST,
8+
PUBLIC_ENVIRONMENT
9+
} from '$env/static/public';
10+
import discordImage from '$lib/images/discord.png';
11+
import { clientFetch } from '$lib/other/clientFetch';
12+
import type { OAuthAuthorizeQuery, OAuthAuthorizeQueryDiscord } from '$lib/types';
13+
import { utility } from '$lib/utility/utility';
14+
import { redirect } from '@sveltejs/kit';
15+
16+
type Props = {
17+
text: string;
18+
className?: string;
19+
};
20+
21+
let { text, className }: Props = $props();
22+
23+
const onclick = async () => {
24+
const query: OAuthAuthorizeQueryDiscord = {
25+
client_id: PUBLIC_DISCORD_OAUTH_CLIENT_ID,
26+
redirect_uri: utility.getRedirectUri("discord"),
27+
response_type: 'code',
28+
scope: 'identify'
29+
};
30+
31+
const baseUrl = new URL('https://discord.com/oauth2/authorize');
32+
33+
for (const [key, value] of utility.betterEntries(query)) {
34+
baseUrl.searchParams.set(key, value);
35+
}
36+
37+
window.location.href = baseUrl.toString();
38+
};
39+
</script>
40+
41+
<button class={['button button-thin flex items-center gap-2', className]} {onclick}>
42+
<span class="font-xx-small">{text}</span>
43+
<img src={discordImage} alt="Icon for Discord" width={18} />
44+
</button>
45+
46+
<style>
47+
.button:hover {
48+
background-color: var(--color-discord-foreground);
49+
}
50+
51+
.button:hover img {
52+
filter: grayscale(100%);
53+
}
54+
</style>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type AuthProviderDiscord = {
2+
DiscordAvatar: string;
3+
DiscordId: bigint;
4+
DiscordUserId: string;
5+
DiscordUsername: string;
6+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type AuthProviderEmail = {
2+
Email: string;
3+
Password: string;
4+
Username: string;
5+
};
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export type MongoUser = {
2-
DiscordId: bigint;
3-
Password: string;
4-
Username: string;
2+
AuthorizationId: string;
3+
AuthorizationMethod: string;
54
};
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
export const ROUTES = {
2-
API: [
3-
'/skyblock/?/create-buy-item',
4-
'/skyblock/?/create-sell-item',
5-
'/api/auctions',
6-
'/api/auctions/buy',
7-
'/api/bazaar',
8-
'/api/bazaar/buy',
9-
'/api/bazaar/sell',
10-
'/api/login'
11-
] as const,
12-
PAGES: ['/discord', '/skyblock', '/skyblock/auctions', '/skyblock/bazaar'] as const
2+
API: ['/api/auctions', '/api/auctions/buy', '/api/bazaar', '/api/bazaar/buy', '/api/bazaar/sell', '/api/login'] as const,
3+
PAGES: ['/discord', '/skyblock', '/skyblock/auctions', '/skyblock/bazaar', '/account/login', '/account/signup'] as const
134
} as const;
145

156
export type Routes = typeof ROUTES;

0 commit comments

Comments
 (0)