Skip to content

Instantly share code, notes, and snippets.

@mattmcmanus
Created June 28, 2011 17:18
Show Gist options
  • Save mattmcmanus/1051647 to your computer and use it in GitHub Desktop.
Save mattmcmanus/1051647 to your computer and use it in GitHub Desktop.
Mongoose-Auth bug?
GET / 6 ms
starting step - getRequestToken
...finished step
starting step - storeRequestToken
...finished step
starting step - redirectToProviderAuth
...finished step
GET /auth/twitter 444 ms
starting step - extractTokenAndVerifier
...finished step
starting step - getSession
...finished step
starting step - rememberTokenSecret
...finished step
starting step - getAccessToken
...finished step
starting step - fetchOAuthUser
...finished step
starting step - findOrCreateUser
...finished step
starting step - compileAuth
...finished step
starting step - addToSession
...finished step
starting step - sendResponse
...finished step
GET /auth/twitter/callback?oauth_token=v1gyFKxxq2beRXi3Ue0kCmey9rU5OWvp1wikVyik1U&oauth_verifier=PGFYUjubP2wuKBxADSWD9GWrePxUk3sjH7vlmQa8UY 1640 ms
====================== req.user ============================================
undefined
====================== /req.user ===========================================
GET / 3 ms
var express = require('express')
, _ = require('underscore')
, sq = require('./lib/statusquo')
// Some Basic variables
, pub = __dirname + '/public'
, views = __dirname + '/views'
sq.settings = JSON.parse(sq.lib.fs.readFileSync('./config.json', 'utf8'))
var Promise = sq.lib.everyauth.Promise;
sq.lib.everyauth.debug = true;
var Schema = sq.lib.mongoose.Schema
, ObjectId = sq.lib.mongoose.SchemaTypes.ObjectId
, mongoose = sq.lib.mongoose
// Users
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var UserSchema = new Schema({})
UserSchema.virtual('id')
.get(function() {
return this._id.toHexString()
})
UserSchema.plugin(sq.lib.mongooseAuth, {
everymodule: {
everyauth: {
User: function () {
return sq.User;
}
}
}
, twitter: {
everyauth: {
myHostname: sq.settings.defaults.myHostname
, consumerKey: sq.settings.defaults.oauthConsumerKey
, consumerSecret: sq.settings.defaults.oauthConsumerSecret
//, authorizePath: '/oauth/authenticate'
, redirectPath: '/'
}
}
, password: {
loginWith: 'email'
, extraParams: {
phone: String
, carrier: String
, name: {
first: String
, last: String
}
}
, everyauth: {
getLoginPath: '/login'
, postLoginPath: '/login'
, loginView: 'user/login.jade'
, getRegisterPath: '/register'
, postRegisterPath: '/register'
, registerView: 'user/register.jade'
, loginSuccessRedirect: '/'
, registerSuccessRedirect: '/'
, displayRegister: function (req, res) {
var user = req.user;
var userParams = {};
sq.debug(user, "displayRegister")
if (user && user.twit && user.twit.name) userParams.name = user.twit.name;
if (user && user.twit && user.twit.screenName) userParams.screenName = user.twit.screenName;
if (user && user.twit && user.twit.profileImageUrl) userParams.profileImageUrl = user.twit.profileImageUrl;
res.render('user/register', { userParams: userParams });
}
}
}
})
UserSchema.pre('save', function(next) {
if (!this.username)
this.username = this.twit.screenName
if (!this.name)
this.name = this.twit.name
next()
})
var app = express.createServer(
)
sq.lib.mongoose.model('User', UserSchema)
sq.lib.mongoose.connect(sq.settings.production['db-uri'])
sq.User = sq.lib.mongoose.model('User')
// Default Config settings
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
app.configure(function(){
// Load default settings from config file
_.each(sq.settings.defaults, function(setting, key) { app.set(key, setting) })
_.each(sq.settings.development, function(setting, key) { app.set(key, setting) })
// Files
app.use(express.static(pub))
app.use(express.favicon())
app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }))
app.use(express.cookieParser())
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.session({ secret: 'qu0'}))
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
app.use(sq.lib.mongooseAuth.middleware())
});
app.get('/', function(req,res){
sq.debug(req.user, "req.user")
res.send("Hellz yeah")
})
sq.lib.mongooseAuth.helpExpress(app);
app.listen(8000)
console.log("- - - - Server started - - - - ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment