mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add username+pass login on NO_AUTH mode
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { createUserJwt } from '~/server/AuthManager';
|
||||
import { UserModel } from '@schema/UserSchema';
|
||||
|
||||
const { NOAUTH_USER_EMAIL, NOAUTH_USER_NAME, public: publicRuntime } = useRuntimeConfig();
|
||||
const { NOAUTH_USER_EMAIL, NOAUTH_USER_PASS, public: publicRuntime } = useRuntimeConfig();
|
||||
|
||||
const noAuthMode = publicRuntime.AUTH_MODE == 'NO_AUTH';
|
||||
|
||||
@@ -18,11 +18,15 @@ export default defineEventHandler(async event => {
|
||||
return { error: true, access_token: '' }
|
||||
}
|
||||
|
||||
if (!NOAUTH_USER_NAME) {
|
||||
console.error('NOAUTH_USER_NAME is required in NO_AUTH mode');
|
||||
if (!NOAUTH_USER_PASS) {
|
||||
console.error('NOAUTH_USER_PASS is required in NO_AUTH mode');
|
||||
return { error: true, access_token: '' }
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
|
||||
if (body.email != NOAUTH_USER_EMAIL || body.password != NOAUTH_USER_PASS) return { error: true, access_token: '', errorMessage: 'Username or password invalid' }
|
||||
|
||||
const user = await UserModel.findOne({ email: NOAUTH_USER_EMAIL });
|
||||
|
||||
if (user) return {
|
||||
@@ -35,8 +39,8 @@ export default defineEventHandler(async event => {
|
||||
|
||||
const newUser = new UserModel({
|
||||
email: NOAUTH_USER_EMAIL,
|
||||
given_name: NOAUTH_USER_NAME,
|
||||
name: NOAUTH_USER_NAME,
|
||||
given_name: NOAUTH_USER_EMAIL.split('@')[0] || 'NONAME',
|
||||
name: NOAUTH_USER_EMAIL.split('@')[0] || 'NONAME',
|
||||
locale: 'no-auth',
|
||||
picture: '',
|
||||
created_at: Date.now()
|
||||
|
||||
Reference in New Issue
Block a user