fix: Allow soft deletion of teams (#1754)

* fix: Allow soft deletion of teams

* test: regression specs
This commit is contained in:
Tom Moor
2020-12-30 09:40:23 -08:00
committed by GitHub
parent 8dba32b5e0
commit ba61091c4c
7 changed files with 137 additions and 33 deletions

View File

@ -1,6 +1,7 @@
// @flow
import crypto from "crypto";
import { OAuth2Client } from "google-auth-library";
import invariant from "invariant";
import Router from "koa-router";
import { capitalize } from "lodash";
import Sequelize from "sequelize";
@ -68,15 +69,24 @@ router.get("google.callback", auth({ required: false }), async (ctx) => {
const cbResponse = await fetch(cbUrl);
const avatarUrl = cbResponse.status === 200 ? cbUrl : tileyUrl;
const [team, isFirstUser] = await Team.findOrCreate({
where: {
googleId,
},
defaults: {
name: teamName,
avatarUrl,
},
});
let team, isFirstUser;
try {
[team, isFirstUser] = await Team.findOrCreate({
where: {
googleId,
},
defaults: {
name: teamName,
avatarUrl,
},
});
} catch (err) {
if (err instanceof Sequelize.UniqueConstraintError) {
ctx.redirect(`/?notice=auth-error`);
return;
}
}
invariant(team, "Team must exist");
try {
const [user, isFirstSignin] = await User.findOrCreate({