addition of new dashboard

This commit is contained in:
2026-08-20 15:08:32 +00:00
parent 0622018d95
commit bf59249ed7
161 changed files with 13170 additions and 119 deletions

View File

@@ -0,0 +1,46 @@
import GoogleStrategy from "passport-google-oauth20";
import { checkUser } from "../../http/auth.js";
import { getConfig } from "../../common/config.js";
const key = 'google';
export function getModuleConfig() {
const config = getConfig();
return {
title: 'Google',
icon: 'language',
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${config.publicCallbackUrl}/callback/${key}`,
}
}
export async function initModule(app, passport) {
const config = getConfig();
passport.use(new GoogleStrategy.Strategy(
config.authModules[key],
function (accessToken, refreshToken, profile, cb) {
(async () => {
try {
const photo = profile.photos?.length > 0 ? profile.photos[0].value : null;
const user = await checkUser(key, 'https://google.com', profile.id, profile.displayName, photo);
return cb(null, user);
} catch (e) {
if (config.debug)
console.error(e);
return cb(null, null);
}
})();
}
));
app.get(`/login/${key}`, passport.authenticate('google', { scope: ['profile'] }));
app.get(`/callback/${key}`,
passport.authenticate('google', {
failureRedirect: '/',
failureMessage: true
}),
function (req, res) {
res.redirect('/home');
}
);
}