Compare commits
2 Commits
12e92b8106
...
d74a51db7f
Author | SHA1 | Date | |
---|---|---|---|
d74a51db7f | |||
11a59d39af |
@ -4,9 +4,9 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await $fetch('/api/auth/user')
|
const user = await $fetch('/api/users/@me')
|
||||||
|
|
||||||
if (!user.id) {
|
if (!user._id) {
|
||||||
throw createError({ statusCode: 500, statusMessage: 'No user was found' })
|
throw createError({ statusCode: 500, statusMessage: 'No user was found' })
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
import * as jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken' //eslint-disable-line
|
||||||
|
|
||||||
type AccessTokenResponse = {
|
type AccessTokenResponse = {
|
||||||
access_token: string,
|
access_token: string,
|
||||||
|
24
webv2/server/api/minecraft/verifyaccount.get.ts
Normal file
24
webv2/server/api/minecraft/verifyaccount.get.ts
Normal file
@ -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)
|
||||||
|
}
|
@ -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<IUser>('User', userSchema)
|
export const UserModel = model<IUser>('User', userSchema)
|
||||||
|
export const WhitelistModel = model<IWhitelist>('Whitelist', whitelistSchema)
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
"extends": "./.nuxt/tsconfig.json",
|
"extends": "./.nuxt/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"typeRoots": ["./types"]
|
"typeRoots": ["./types"]
|
||||||
}
|
},
|
||||||
|
"esModuleInterop": true
|
||||||
}
|
}
|
||||||
|
7
webv2/types/global.d.ts
vendored
7
webv2/types/global.d.ts
vendored
@ -21,4 +21,11 @@ declare global {
|
|||||||
teamId: string,
|
teamId: string,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IWhitelist {
|
||||||
|
_id: string,
|
||||||
|
uuid: string,
|
||||||
|
connected: boolean,
|
||||||
|
code: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user