jaredden1 / Get-Me-Fit-App

Get Me Fit
https://get-fit-tracker-1b767e883070.herokuapp.com/
MIT License
0 stars 2 forks source link

Glow Snippet - AAG #20

Open harrymohney opened 1 year ago

harrymohney commented 1 year ago

Great personalized feature adding in OAuth to track specific user data.

`const passport = require('passport'); const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy; const User = require('../models/user');

passport.use(new GoogleStrategy( // Configuration object { clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_SECRET, callbackURL: process.env.GOOGLE_CALLBACK }, async function(accessToken, refreshToken, profile, cb) { try { let user = await User.findOne({ googleId: profile.id }) if (user) return cb(null, user) user = await User.create({ name: profile.displayName, googleId: profile.id, email: profile.emails[0].value, avatar: profile.photos[0].value }) return cb(null, user); } catch (err) { return cb(err)

    }
}

));

passport.serializeUser(function(user, cb) { cb(null, user._id); });

passport.deserializeUser(async function(userId, cb) { cb(null, await User.findById(userId)); });`

maker-jws commented 1 year ago

I am not quite sure how you customized the passport implementation shown in your code snippet, but having access to user data on every route is definitely a great opportunity for personalization at the template level. If you have begin researching req and response cookie implementation in express it might even be possible to store the ids of the 3-5 most recent workouts in a browser cookie. This ‘history’ could then be checked when accessing a ‘recent’ / workout page, perhaps these features could even be the core of a user profile page.

Great work getting Authentication / Authorization started with Express - definitely a whole order of magnitude more complex but does provide the user a more custom/personalized experience - definitely a big win!