mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
fix: remove default user
This commit is contained in:
1 parent
f18ec35a9f
commit
c551f0c92b
2 files changed
+2
-18
No files matched your search
@@ -15,7 +15,6 @@ import errorHandler from './middleware/error.js'
|
|||||||
import globalRateLimit from './middleware/globalRateLimit.js'
|
import globalRateLimit from './middleware/globalRateLimit.js'
|
||||||
import sessionMiddleware from './middleware/session.js'
|
import sessionMiddleware from './middleware/session.js'
|
||||||
import expiryRemovalScheduler from './containers/expiryChecker.js'
|
import expiryRemovalScheduler from './containers/expiryChecker.js'
|
||||||
import { createTestUser } from './utils/auth.js'
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
@@ -26,8 +25,6 @@ async function main() {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
await createTestUser()
|
|
||||||
|
|
||||||
await loadAndUpdateQuests()
|
await loadAndUpdateQuests()
|
||||||
expiryRemovalScheduler()
|
expiryRemovalScheduler()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import { User } from '@linux-odyssey/models'
|
|
||||||
import bcrypt from 'bcrypt'
|
import bcrypt from 'bcrypt'
|
||||||
import config from '../config.js'
|
import config from '../config.js'
|
||||||
|
|
||||||
@@ -7,23 +6,11 @@ export function hashPassword(password) {
|
|||||||
return bcrypt.hash(password, 10)
|
return bcrypt.hash(password, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTestUser() {
|
|
||||||
let user = await User.findOne({ username: 'alex' })
|
|
||||||
if (!user) {
|
|
||||||
user = new User({
|
|
||||||
username: 'alex',
|
|
||||||
email: 'alex@example.com',
|
|
||||||
})
|
|
||||||
user.hashedPassword = await hashPassword('123456')
|
|
||||||
await user.save()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function genJWT(payload) {
|
export function genJWT(payload) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
jwt.sign(
|
jwt.sign(
|
||||||
payload,
|
payload,
|
||||||
config.jwtSecret,
|
config.secret,
|
||||||
{ expiresIn: config.containerExpiry },
|
{ expiresIn: config.containerExpiry },
|
||||||
(err, token) => {
|
(err, token) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -38,7 +25,7 @@ export function genJWT(payload) {
|
|||||||
|
|
||||||
export function verifyJWT(token) {
|
export function verifyJWT(token) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
jwt.verify(token, config.jwtSecret, (err, decoded) => {
|
jwt.verify(token, config.secret, (err, decoded) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user