mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add no_auth login
This commit is contained in:
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
|
|
||||||
const gooleSignInConfig: any = {
|
const gooleSignInConfig: any = {
|
||||||
googleSignIn: {
|
googleSignIn: {
|
||||||
clientId: process.env.GOOGLE_AUTH_CLIENT_ID
|
clientId: process.env.GOOGLE_AUTH_CLIENT_ID || 'NONE'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +43,8 @@ export default defineNuxtConfig({
|
|||||||
STRIPE_WH_SECRET: process.env.STRIPE_WH_SECRET,
|
STRIPE_WH_SECRET: process.env.STRIPE_WH_SECRET,
|
||||||
STRIPE_SECRET_TEST: process.env.STRIPE_SECRET_TEST,
|
STRIPE_SECRET_TEST: process.env.STRIPE_SECRET_TEST,
|
||||||
STRIPE_WH_SECRET_TEST: process.env.STRIPE_WH_SECRET_TEST,
|
STRIPE_WH_SECRET_TEST: process.env.STRIPE_WH_SECRET_TEST,
|
||||||
|
NOAUTH_USER_EMAIL: process.env.NOAUTH_USER_EMAIL,
|
||||||
|
NOAUTH_USER_NAME: process.env.NOAUTH_USER_NAME,
|
||||||
public: {
|
public: {
|
||||||
PAYPAL_CLIENT_ID: ''
|
PAYPAL_CLIENT_ID: ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,41 @@
|
|||||||
|
|
||||||
definePageMeta({ layout: 'none' });
|
definePageMeta({ layout: 'none' });
|
||||||
|
|
||||||
|
const { GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig();
|
||||||
|
|
||||||
const { isReady, login } = useCodeClient({ onSuccess: handleOnSuccess, onError: handleOnError, });
|
const isNoAuth = ref<boolean>(GOOGLE_AUTH_CLIENT_ID == undefined);
|
||||||
|
|
||||||
|
const useCodeClientWrapper = isNoAuth.value === true ? useCodeClient : (...args: any) => {
|
||||||
|
return { isReady: false, login: () => { } }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loginWithoutAuth() {
|
||||||
|
try {
|
||||||
|
const result = await $fetch('/api/auth/no_auth');
|
||||||
|
if (result.error) return alert('Error during login, please try again');
|
||||||
|
|
||||||
|
setToken(result.access_token);
|
||||||
|
|
||||||
|
const user = await $fetch<any>('/api/user/me', { headers: { 'Authorization': 'Bearer ' + token.value } })
|
||||||
|
const loggedUser = useLoggedUser();
|
||||||
|
loggedUser.value = user;
|
||||||
|
|
||||||
|
console.log('LOGIN DONE - USER', loggedUser.value);
|
||||||
|
|
||||||
|
const isFirstTime = await $fetch<boolean>('/api/user/is_first_time', { headers: { 'Authorization': 'Bearer ' + token.value } })
|
||||||
|
|
||||||
|
if (isFirstTime === true) {
|
||||||
|
router.push('/project_creation?just_logged=true');
|
||||||
|
} else {
|
||||||
|
router.push('/?just_logged=true');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
alert('Error during login.', ex.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { isReady, login } = useCodeClientWrapper({ onSuccess: handleOnSuccess, onError: handleOnError, });
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -80,7 +113,7 @@ function handleOnError(errorResponse: any) {
|
|||||||
|
|
||||||
<div class="mt-12">
|
<div class="mt-12">
|
||||||
|
|
||||||
<div @click="login"
|
<div v-if="!isNoAuth" @click="login"
|
||||||
class="hover:bg-accent cursor-pointer flex text-[1.3rem] gap-4 items-center border-[1px] border-gray-400 rounded-lg px-8 py-3 relative z-[2]">
|
class="hover:bg-accent cursor-pointer flex text-[1.3rem] gap-4 items-center border-[1px] border-gray-400 rounded-lg px-8 py-3 relative z-[2]">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<i class="fab fa-google"></i>
|
<i class="fab fa-google"></i>
|
||||||
@@ -88,6 +121,14 @@ function handleOnError(errorResponse: any) {
|
|||||||
Continue with Google
|
Continue with Google
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isNoAuth" @click="loginWithoutAuth"
|
||||||
|
class="hover:bg-accent cursor-pointer flex text-[1.3rem] gap-4 items-center border-[1px] border-gray-400 rounded-lg px-8 py-3 relative z-[2]">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<i class="far fa-crown"></i>
|
||||||
|
</div>
|
||||||
|
Continue as Admin
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-[.9rem] poppins mt-12 text-text-sub text-center relative z-[2]">
|
<div class="text-[.9rem] poppins mt-12 text-text-sub text-center relative z-[2]">
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import { OAuth2Client } from 'google-auth-library';
|
|||||||
import { createUserJwt } from '~/server/AuthManager';
|
import { createUserJwt } from '~/server/AuthManager';
|
||||||
import { UserModel } from '@schema/UserSchema';
|
import { UserModel } from '@schema/UserSchema';
|
||||||
import EmailService from '@services/EmailService';
|
import EmailService from '@services/EmailService';
|
||||||
import { ProjectModel } from '@schema/ProjectSchema';
|
|
||||||
import StripeService from '~/server/services/StripeService';
|
|
||||||
|
|
||||||
const { GOOGLE_AUTH_CLIENT_SECRET, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig()
|
const { GOOGLE_AUTH_CLIENT_SECRET, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig()
|
||||||
|
|
||||||
|
|||||||
49
dashboard/server/api/auth/no_auth.ts
Normal file
49
dashboard/server/api/auth/no_auth.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
import { createUserJwt } from '~/server/AuthManager';
|
||||||
|
import { UserModel } from '@schema/UserSchema';
|
||||||
|
|
||||||
|
const { NOAUTH_USER_EMAIL, NOAUTH_USER_NAME, GOOGLE_AUTH_CLIENT_ID } = useRuntimeConfig();
|
||||||
|
|
||||||
|
const noAuthMode = GOOGLE_AUTH_CLIENT_ID.length == 0;
|
||||||
|
|
||||||
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
if (!noAuthMode) {
|
||||||
|
console.error('Endpoint available only in NO_AUTH mode');
|
||||||
|
return { error: true, access_token: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NOAUTH_USER_EMAIL) {
|
||||||
|
console.error('NOAUTH_USER_EMAIL is required in NO_AUTH mode');
|
||||||
|
return { error: true, access_token: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NOAUTH_USER_NAME) {
|
||||||
|
console.error('NOAUTH_USER_NAME is required in NO_AUTH mode');
|
||||||
|
return { error: true, access_token: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await UserModel.findOne({ email: NOAUTH_USER_EMAIL });
|
||||||
|
|
||||||
|
if (user) return {
|
||||||
|
error: false,
|
||||||
|
access_token: createUserJwt({
|
||||||
|
email: user.email,
|
||||||
|
name: user.name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const newUser = new UserModel({
|
||||||
|
email: NOAUTH_USER_EMAIL,
|
||||||
|
given_name: NOAUTH_USER_NAME,
|
||||||
|
name: NOAUTH_USER_NAME,
|
||||||
|
locale: 'no-auth',
|
||||||
|
picture: '',
|
||||||
|
created_at: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
const savedUser = await newUser.save();
|
||||||
|
|
||||||
|
return { error: false, access_token: createUserJwt({ email: savedUser.email, name: savedUser.name }) }
|
||||||
|
|
||||||
|
});
|
||||||
@@ -85,10 +85,16 @@ services:
|
|||||||
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
||||||
|
|
||||||
|
|
||||||
# Used to register / login
|
# Optional - Used to register / login via google
|
||||||
|
|
||||||
NUXT_GOOGLE_AUTH_CLIENT_ID: ""
|
# NUXT_GOOGLE_AUTH_CLIENT_ID: ""
|
||||||
NUXT_GOOGLE_AUTH_CLIENT_SECRET: ""
|
# NUXT_GOOGLE_AUTH_CLIENT_SECRET: ""
|
||||||
|
|
||||||
|
|
||||||
|
# Default user created to login if no GOOGLE_AUTH_CLIENT_ID is provided
|
||||||
|
|
||||||
|
NOAUTH_USER_EMAIL: 'default@user.com'
|
||||||
|
NOAUTH_USER_NAME: "defaultuser"
|
||||||
|
|
||||||
|
|
||||||
# Optional - Used for tests
|
# Optional - Used for tests
|
||||||
@@ -99,16 +105,16 @@ services:
|
|||||||
|
|
||||||
# Optional - Stripe secret - Used to change plans of the projects
|
# Optional - Stripe secret - Used to change plans of the projects
|
||||||
|
|
||||||
#NUXT_STRIPE_SECRET: ""
|
# NUXT_STRIPE_SECRET: ""
|
||||||
#NUXT_STRIPE_WH_SECRET: ""
|
# NUXT_STRIPE_WH_SECRET: ""
|
||||||
|
|
||||||
build:
|
build:
|
||||||
dockerfile: ./dashboard/Dockerfile
|
dockerfile: ./dashboard/Dockerfile
|
||||||
args:
|
#args:
|
||||||
|
|
||||||
# Used to register / login
|
# Optional - Used to register / login via google
|
||||||
|
|
||||||
GOOGLE_AUTH_CLIENT_ID: ""
|
# GOOGLE_AUTH_CLIENT_ID: ""
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mongo-data:
|
mongo-data:
|
||||||
|
|||||||
Reference in New Issue
Block a user