Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4244 from withspectrum/fix-cookie-setting-with-em…
Browse files Browse the repository at this point in the history
…ail-changes

Update the user cookie when confirming an email
  • Loading branch information
brianlovin authored Nov 14, 2018
2 parents d61e3b6 + 0ed077b commit 281499e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions api/queries/user/rootCurrentUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// @flow
import type { GraphQLContext } from '../../';
import { getUserById } from 'shared/db/queries/user';

export default (_: any, __: any, { user }: GraphQLContext) =>
user ? (user.bannedAt ? null : user) : null;
export default async (_: any, __: any, { user }: GraphQLContext) => {
if (!user || !user.id) return null;
const dbUser = await getUserById(user.id);
if (!dbUser || dbUser.bannedAt) return null;
return dbUser;
};
15 changes: 13 additions & 2 deletions api/routes/api/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,19 @@ emailRouter.get('/validate', (req, res) => {
const rootRedirect = IS_PROD
? `https://spectrum.chat`
: `http://localhost:3000`;
if (!user.username) return res.redirect(rootRedirect);
return res.redirect(`${rootRedirect}/users/${user.username}/settings`);

req.login(user, err => {
if (err) {
return res
.status(400)
.send(
'We ran into an issue validating this email address. You can re-enter your email address in your community settings to resend a confirmation email, or get in touch with us at [email protected].'
);
}

if (!user.username) return res.redirect(rootRedirect);
return res.redirect(`${rootRedirect}/users/${user.username}/settings`);
});
});
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 281499e

Please sign in to comment.