diff --git a/webv2/middleware/auth.js b/webv2/middleware/auth.ts similarity index 100% rename from webv2/middleware/auth.js rename to webv2/middleware/auth.ts diff --git a/webv2/server/api/minecraft/verifyaccount.get.ts b/webv2/server/api/minecraft/verifyaccount.get.ts new file mode 100644 index 0000000..5bc6a8d --- /dev/null +++ b/webv2/server/api/minecraft/verifyaccount.get.ts @@ -0,0 +1,24 @@ +export default defineEventHandler(async (event) => { + const { uuid } = getQuery(event) + + let whitelistDoc + try { + whitelistDoc = await WhitelistModel.findOneAndUpdate({ uuid }, { + $set: { + uuid + }, + $setOnInsert: { + code: generateCode(), + connected: false + } + }, { returnDocument: 'after', upsert: true }) + + return whitelistDoc + } catch (e: any) { + throw createError({ statusCode: 500, statusMessage: 'Failed to update/insert whitelist document' }) + } +}) + +const generateCode = () => { + return Math.floor(100000 + Math.random() * 900000) +} diff --git a/webv2/server/utils/models.ts b/webv2/server/utils/models.ts index e31048e..d64ae4e 100644 --- a/webv2/server/utils/models.ts +++ b/webv2/server/utils/models.ts @@ -21,4 +21,11 @@ const userSchema = new Schema({ ] }) +const whitelistSchema = new Schema({ + uuid: { type: String, required: true, unique: true }, + connected: { type: Boolean, required: true, default: false }, + code: { type: String, required: true, unique: true, length: 6 } +}) + export const UserModel = model('User', userSchema) +export const WhitelistModel = model('Whitelist', whitelistSchema) diff --git a/webv2/types/global.d.ts b/webv2/types/global.d.ts index 98a452d..2175ac9 100644 --- a/webv2/types/global.d.ts +++ b/webv2/types/global.d.ts @@ -21,4 +21,11 @@ declare global { teamId: string, accessToken?: string } + + interface IWhitelist { + _id: string, + uuid: string, + connected: boolean, + code: string + } }