-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* signup now in two stages; create firebase account, and create profile * signup flow more logical now ... handles most edge cases pretty well * basic profile page - still buggy, non functional update profile button * local default picture * update user backend added... no tests * lint errors fixed * working profile update * fixed textarea stuff, watcher to fix refresh profile problem * profile picture update added * working password reset from login form * nice error message for non-unique username * made hasProfile dependent on isLoggedIn to alleviate some potential bad * removed TODO * fixed post review/question bug when logged in * loading state for nav, split auth and profile get into two bits * reverted some stuff ... working again * better auth code, profile cache, global loading spinner in nav, reroutes * lint * page size fixaroo * I'v messed something up * protecting routes with guards * fixed some PR things * smol fixes * removed preAuth route check - not needed rn * smol fix to login page reroute
- Loading branch information
1 parent
43e726d
commit d639762
Showing
27 changed files
with
622 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,26 @@ const userModel = require('../models/user')() | |
const { responseHandler } = require('../utils/helpers') | ||
|
||
/* Get data for a specific user */ | ||
exports.getUser = function(_, res) { | ||
return res.json({ | ||
userID: 1, | ||
firstName: 'Walker', | ||
lastName: 'Francis', | ||
email: '[email protected]' | ||
}) | ||
exports.getUser = function({id}, res) { | ||
return responseHandler(userModel.getPublicProfile(id), res) | ||
.catch(errorHandler(res)) | ||
} | ||
|
||
/** | ||
* user must be auth'd, | ||
* provide frontend with any user specific data | ||
*/ | ||
exports.getSelf = function(req, res) { | ||
const errorResponse = errorHandler(res) | ||
if (!req.user) { | ||
return errorResponse({ message: 'Invalid Credentials' }) | ||
} | ||
// fine for now, should include profile data | ||
return res.json(req.user) | ||
return responseHandler(userModel.getProfile(req.user.id), res) | ||
.catch(errorHandler(res)) | ||
} | ||
|
||
exports.createUser = function({ authorized: { email, uid }, body: { displayName } }, res) { | ||
return responseHandler(userModel.createUser({ email, uid, displayName }), res) | ||
.catch(errorHandler(res)) | ||
} | ||
|
||
exports.createUser = function({ authorized }, res) { | ||
return responseHandler(userModel.createUser(authorized), res) | ||
exports.updateUser = function({ user: { id }, body: { degree, gradYear, description, picture } }, res) { | ||
return responseHandler(userModel.updateUser(id, { degree, gradYear, description, picture }), res) | ||
.catch(errorHandler(res)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
const express = require('express') | ||
const router = express.Router() | ||
const { isAuthorized } = require('../utils/helpers') | ||
const { getSelf, getUser, createUser } = require('../controllers/user') | ||
const { isAuthorized, isFirebaseAuthorized } = require('../utils/helpers') | ||
const { getSelf, getUser, createUser, updateUser } = require('../controllers/user') | ||
|
||
/* Get data for a specific user */ | ||
/* Get public data for a specific user */ | ||
router.get('/:id', getUser) | ||
|
||
/* no valid jwt then don't allow user to be created */ | ||
router.use(isFirebaseAuthorized) | ||
router.post('/', createUser) | ||
|
||
/* full auth check */ | ||
router.use(isAuthorized) | ||
|
||
/** | ||
* Both of these require an authorization header | ||
* provide frontend with any user specific data | ||
*/ | ||
/* provide frontend with any user specific data */ | ||
router.get('/', getSelf) | ||
router.put('/', updateUser) | ||
|
||
router.post('/', createUser) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { expect } = require('chai') | ||
// use an actual database | ||
const userModel = require('../../src/models/user')(require('../../src/models/db')) | ||
|
||
describe('User Model', () => { | ||
|
||
it('compiles', function () { | ||
expect(userModel) | ||
}) | ||
|
||
describe('User creation and retrieval', () => { | ||
const addUserObj = { displayName: 'mickey', email: '[email protected]', uid: '1234' } | ||
const retrieveUserObj = { email: addUserObj.email, displayName: addUserObj.displayName, degree:null, gradYear:null, description:null, picture:null } | ||
it('it creates a user and retrieves the profile', () => { | ||
return userModel | ||
.createUser(addUserObj) | ||
.then(({ displayName, email, id }) => { | ||
expect(displayName).to.equal(addUserObj.displayName) | ||
expect(email).to.equal(addUserObj.email) | ||
return userModel.getProfile(id) | ||
}) | ||
.then(({ email, displayName, degree, gradYear, description, picture }) => { | ||
const profile = { email, displayName, degree, gradYear, description, picture } | ||
expect(profile).to.deep.equal(retrieveUserObj) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('User update', () => { | ||
const credsObj = { displayName: 'mickeyMoo', email: '[email protected]' } | ||
const addUserObj = { ...credsObj, uid: '4321' } | ||
const updateObj = { degree: "BS in CS", gradYear: 2026, description: "testu", picture: "baaaaaa" } | ||
it('it updates the profile correctly', () => { | ||
return userModel | ||
.createUser(addUserObj) | ||
.then(({ id, description }) => { | ||
return userModel.updateUser(id, updateObj) | ||
}) | ||
.then(({ email, displayName, degree, gradYear, description, picture }) => { | ||
const profile = { email, displayName, degree, gradYear, description, picture } | ||
expect(profile).to.deep.equal({ ...credsObj, ...updateObj }) | ||
}) | ||
}) | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.