mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
ready to test
Testing Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
require('dotenv').config();
|
||||
|
||||
const useSSL = process.env.DB_SSL !== 'false';
|
||||
|
||||
const base = {
|
||||
username: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
host: process.env.DB_HOST,
|
||||
port: parseInt(process.env.DB_PORT, 10) || 26257,
|
||||
dialect: 'postgres',
|
||||
dialectOptions: {
|
||||
...(useSSL && {
|
||||
ssl: {
|
||||
require: true,
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
development: base,
|
||||
production: base,
|
||||
};
|
||||
+8
-4
@@ -14,6 +14,8 @@
|
||||
require('dotenv').config();
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const useSSL = process.env.DB_SSL !== 'false';
|
||||
|
||||
const sequelize = new Sequelize(
|
||||
process.env.DB_NAME,
|
||||
process.env.DB_USER,
|
||||
@@ -23,10 +25,12 @@ const sequelize = new Sequelize(
|
||||
port: process.env.DB_PORT || 5432,
|
||||
dialect: 'postgres',
|
||||
dialectOptions: {
|
||||
ssl: {
|
||||
require: true,
|
||||
rejectUnauthorized: false, // or provide CA cert if strict
|
||||
},
|
||||
...(useSSL && {
|
||||
ssl: {
|
||||
require: true,
|
||||
rejectUnauthorized: false, // or provide CA cert if strict
|
||||
},
|
||||
}),
|
||||
},
|
||||
// logging: process.env.NODE_ENV === 'development' ? console.log : false,
|
||||
logging: false,
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: passport.config.js
|
||||
* Type of Program: Configuration
|
||||
* Description: Passport.js strategy configuration.
|
||||
* Registers the Google OAuth 2.0 strategy. On first login via Google
|
||||
* a new user record is auto-created with reg_type="google".
|
||||
* Returns a signed JWT payload after successful authentication.
|
||||
* Author: rgrgogu
|
||||
* Date Created: Oct. 6, 2025
|
||||
***********************************************************************************************************************************************************************
|
||||
* HOW TO USE:
|
||||
* In server.js:
|
||||
* require('./config/passport.config');
|
||||
* app.use(passport.initialize());
|
||||
* In routes:
|
||||
* router.get('/google', passport.authenticate('google', { scope: ['profile', 'email'] }));
|
||||
* router.get('/google/callback', passport.authenticate('google', { session: false }), handler);
|
||||
***********************************************************************************************************************************************************************/
|
||||
const passport = require('passport');
|
||||
const { Strategy: GoogleStrategy } = require('passport-google-oauth20');
|
||||
const mdl_Users = require('../models/users/users.mdl');
|
||||
|
||||
passport.use(
|
||||
new GoogleStrategy(
|
||||
{
|
||||
clientID: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
callbackURL: process.env.GOOGLE_CALLBACK_URL,
|
||||
},
|
||||
async (accessToken, refreshToken, profile, done) => {
|
||||
try {
|
||||
const email = profile.emails?.[0]?.value;
|
||||
if (!email) return done(new Error('No email returned from Google'), null);
|
||||
|
||||
let user = await mdl_Users.findOne({ where: { email } });
|
||||
|
||||
if (!user) {
|
||||
// Auto-register Google users as 'user' acc_type
|
||||
user = await mdl_Users.create({
|
||||
email,
|
||||
reg_type: 'google',
|
||||
acc_type: 'user',
|
||||
is_active: true,
|
||||
is_verified: true, // Google accounts are pre-verified
|
||||
personal_info: {
|
||||
name: {
|
||||
given_name: profile.name?.givenName || '',
|
||||
last_name: profile.name?.familyName || '',
|
||||
full_name: profile.displayName || '',
|
||||
},
|
||||
avatar: {
|
||||
url: profile.photos?.[0]?.value || null,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!user.is_active) {
|
||||
return done(null, false, { message: 'Account is deactivated.' });
|
||||
}
|
||||
|
||||
return done(null, user);
|
||||
} catch (err) {
|
||||
return done(err, null);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
module.exports = passport;
|
||||
@@ -0,0 +1,25 @@
|
||||
// Returns a connected Redis/Valkey client, or null when CACHE_DRIVER=memory.
|
||||
// Consumers must check for null before using Redis-specific features.
|
||||
// Use case: when project is going to have LiveView in future.
|
||||
|
||||
const useRedis = process.env.CACHE_DRIVER !== 'memory';
|
||||
|
||||
if (!useRedis) {
|
||||
console.log('ℹ️ Cache driver: memory (Redis skipped)');
|
||||
module.exports = null;
|
||||
} else {
|
||||
const { createClient } = require('redis');
|
||||
|
||||
const client = createClient({
|
||||
url: process.env.REDIS_URL || 'redis://127.0.0.1:6379',
|
||||
});
|
||||
|
||||
client.on('error', (err) => console.error('[Redis] Connection error:', err));
|
||||
|
||||
(async () => {
|
||||
await client.connect();
|
||||
console.log('✅ Redis connected.');
|
||||
})();
|
||||
|
||||
module.exports = client;
|
||||
}
|
||||
Reference in New Issue
Block a user