diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index 7e5d4de..5de85d3 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -19,6 +19,6 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'pnpm' - name: Install dependencies - run: pnpm install + run: pnpm add --global turbo && pnpm install - name: Typecheck the webservice run: pnpm check diff --git a/apps/webstack/src/routes/auth/osu/callback/+server.ts b/apps/webstack/src/routes/auth/osu/callback/+server.ts index 8bfe4ee..2a20e52 100644 --- a/apps/webstack/src/routes/auth/osu/callback/+server.ts +++ b/apps/webstack/src/routes/auth/osu/callback/+server.ts @@ -3,6 +3,7 @@ import { env as pubEnv } from '$env/dynamic/public'; import { redirect } from '@sveltejs/kit'; import type { RequestHandler } from './$types'; import { DateTime } from "luxon"; +import { isUserEligible } from 'config'; import type { OsuUser } from '$lib/OsuUser'; async function getOAuthTokens(code: string) { @@ -48,32 +49,17 @@ async function getUserData(tokens: { } } -/** - * @description This function is used to check if the user is eligible for the verified role(s) specfied in your config. - * The default is to check if the user is older than 6 months. - * You can modify the function to check for other things, such as if the user has a certain amount of playtime, rank or pp. - * @param userData The osu! profile of the user. - * @returns A boolean indicating if the user is eligible for the linked role. - * -*/ -function isUserEligible(userData: OsuUser): boolean { - const joinDate = DateTime.fromISO(userData.join_date); - const nowMinus6Months = DateTime.now().minus({ months: 6 }); - - return nowMinus6Months > joinDate; -} - // Write cookie for the state which will be used to compare later for the linked role stuff. export const GET = (async ({ url, locals }) => { try { const code = url.searchParams.get('code'); if (!code) throw new Error('No code provided'); const tokens = await getOAuthTokens(code); - const meData = await getUserData(tokens); + const meData = await getUserData(tokens) as OsuUser; await locals.session.set({ osu: { - id: meData.id, + id: meData.id.toString(), username: meData.username, joinDate: DateTime.fromISO(meData.join_date) } diff --git a/package.json b/package.json index ad73e9d..4e60860 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "dev": "dotenv -- turbo dev", "lint": "turbo run lint", "build": "turbo run build", + "check": "turbo run check", "format": "prettier --write \"**/*.{ts,tsx,md}\"" }, "packageManager": "pnpm@7.29.0", diff --git a/packages/config/config.ts b/packages/config/config.ts index ebf6bb3..ede7423 100644 --- a/packages/config/config.ts +++ b/packages/config/config.ts @@ -1,4 +1,6 @@ +import type { OsuUser } from "../../apps/webstack/src/lib/OsuUser"; import type { ITournamentConfig } from "./config.interface"; +import { DateTime } from "luxon"; export const config: ITournamentConfig = { "host": "Example Host", @@ -15,3 +17,18 @@ export const config: ITournamentConfig = { ] } } + +/** + * @description This function is used to check if the user is eligible for the verified role(s) specfied in your config. + * The default is to check if the user is older than 6 months. + * You can modify the function to check for other things, such as if the user has a certain amount of playtime, rank or pp. + * @param userData The osu! profile of the user. + * @returns A boolean indicating if the user is eligible for the linked role. + * +*/ +export function isUserEligible(userData: OsuUser): boolean { + const joinDate = DateTime.fromISO(userData.join_date); + const nowMinus6Months = DateTime.now().minus({ months: 6 }); + + return nowMinus6Months > joinDate; +} \ No newline at end of file diff --git a/packages/config/package.json b/packages/config/package.json index 0b2d2f6..f643397 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,5 +1,9 @@ { "name": "config", "version": "0.0.0", - "main": "index.ts" + "main": "index.ts", + "dependencies": { + "@types/luxon": "^3.2.0", + "luxon": "^3.3.0" + } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd56776..9232940 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -80,7 +80,12 @@ importers: vitest: 0.25.8 packages/config: - specifiers: {} + specifiers: + '@types/luxon': ^3.2.0 + luxon: ^3.3.0 + dependencies: + '@types/luxon': 3.2.0 + luxon: 3.3.0 packages: