Skip to content

Commit 9ee4cb8

Browse files
authored
Merge pull request #5 from MiraiSubject/module-user-eligibility
Move eligibility check into the configuration module
2 parents c2551cf + e8f336e commit 9ee4cb8

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

.github/workflows/typecheck.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ jobs:
1919
node-version: ${{ matrix.node-version }}
2020
cache: 'pnpm'
2121
- name: Install dependencies
22-
run: pnpm install
22+
run: pnpm add --global turbo && pnpm install
2323
- name: Typecheck the webservice
2424
run: pnpm check

apps/webstack/src/routes/auth/osu/callback/+server.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { env as pubEnv } from '$env/dynamic/public';
33
import { redirect } from '@sveltejs/kit';
44
import type { RequestHandler } from './$types';
55
import { DateTime } from "luxon";
6+
import { isUserEligible } from 'config';
67
import type { OsuUser } from '$lib/OsuUser';
78

89
async function getOAuthTokens(code: string) {
@@ -48,32 +49,17 @@ async function getUserData(tokens: {
4849
}
4950
}
5051

51-
/**
52-
* @description This function is used to check if the user is eligible for the verified role(s) specfied in your config.
53-
* The default is to check if the user is older than 6 months.
54-
* You can modify the function to check for other things, such as if the user has a certain amount of playtime, rank or pp.
55-
* @param userData The osu! profile of the user.
56-
* @returns A boolean indicating if the user is eligible for the linked role.
57-
*
58-
*/
59-
function isUserEligible(userData: OsuUser): boolean {
60-
const joinDate = DateTime.fromISO(userData.join_date);
61-
const nowMinus6Months = DateTime.now().minus({ months: 6 });
62-
63-
return nowMinus6Months > joinDate;
64-
}
65-
6652
// Write cookie for the state which will be used to compare later for the linked role stuff.
6753
export const GET = (async ({ url, locals }) => {
6854
try {
6955
const code = url.searchParams.get('code');
7056
if (!code) throw new Error('No code provided');
7157
const tokens = await getOAuthTokens(code);
72-
const meData = await getUserData(tokens);
58+
const meData = await getUserData(tokens) as OsuUser;
7359

7460
await locals.session.set({
7561
osu: {
76-
id: meData.id,
62+
id: meData.id.toString(),
7763
username: meData.username,
7864
joinDate: DateTime.fromISO(meData.join_date)
7965
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dev": "dotenv -- turbo dev",
55
"lint": "turbo run lint",
66
"build": "turbo run build",
7+
"check": "turbo run check",
78
"format": "prettier --write \"**/*.{ts,tsx,md}\""
89
},
910
"packageManager": "[email protected]",

packages/config/config.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import type { OsuUser } from "../../apps/webstack/src/lib/OsuUser";
12
import type { ITournamentConfig } from "./config.interface";
3+
import { DateTime } from "luxon";
24

35
export const config: ITournamentConfig = {
46
"host": "Example Host",
@@ -15,3 +17,18 @@ export const config: ITournamentConfig = {
1517
]
1618
}
1719
}
20+
21+
/**
22+
* @description This function is used to check if the user is eligible for the verified role(s) specfied in your config.
23+
* The default is to check if the user is older than 6 months.
24+
* You can modify the function to check for other things, such as if the user has a certain amount of playtime, rank or pp.
25+
* @param userData The osu! profile of the user.
26+
* @returns A boolean indicating if the user is eligible for the linked role.
27+
*
28+
*/
29+
export function isUserEligible(userData: OsuUser): boolean {
30+
const joinDate = DateTime.fromISO(userData.join_date);
31+
const nowMinus6Months = DateTime.now().minus({ months: 6 });
32+
33+
return nowMinus6Months > joinDate;
34+
}

packages/config/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"name": "config",
33
"version": "0.0.0",
4-
"main": "index.ts"
4+
"main": "index.ts",
5+
"dependencies": {
6+
"@types/luxon": "^3.2.0",
7+
"luxon": "^3.3.0"
8+
}
59
}

pnpm-lock.yaml

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)