fix: Allow soft deletion of teams (#1754)
* fix: Allow soft deletion of teams * test: regression specs
This commit is contained in:
@ -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({
|
||||
|
Reference in New Issue
Block a user