chore(api/users&/twitter): no need to create a bucket when signup a user

This commit is contained in:
Aminejv 2023-01-17 16:55:24 +01:00
parent bddcb9bd51
commit e677b9aeb7
6 changed files with 2 additions and 108 deletions

View File

@ -81,25 +81,12 @@ export default async (req, res) => {
return res.status(201).send({ decorator: "SERVER_CREATE_USER_USERNAME_TAKEN" });
}
const { textileKey, textileToken, textileThreadID, textileBucketCID } =
await Utilities.createBucket({});
if (!textileKey || !textileToken || !textileThreadID || !textileBucketCID) {
return res
.status(500)
.send({ decorator: "SERVER_CREATE_USER_BUCKET_INIT_FAILURE", error: true });
}
const user = await Data.createUser({
username: newUsername,
email: newEmail,
twitterId: twitterUser.id_str,
twitterUsername: twitterUser.screen_name,
twitterVerified: twitterUser.verified,
textileKey,
textileToken,
textileThreadID,
textileBucketCID,
});
if (!user) {

View File

@ -1,6 +1,5 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Strings from "~/common/strings";
import * as Validations from "~/common/validations";
@ -56,25 +55,12 @@ export default async (req, res) => {
return res.status(201).send({ decorator: "SERVER_CREATE_USER_USERNAME_TAKEN" });
}
const { textileKey, textileToken, textileThreadID, textileBucketCID } =
await Utilities.createBucket({});
if (!textileKey || !textileToken || !textileThreadID || !textileBucketCID) {
return res
.status(500)
.send({ decorator: "SERVER_CREATE_USER_BUCKET_INIT_FAILURE", error: true });
}
const user = await Data.createUser({
username: newUsername,
email: newEmail,
twitterId: twitterUser.id_str,
twitterUsername: twitterUser.screen_name,
twitterVerified: twitterUser.verified,
textileKey,
textileToken,
textileThreadID,
textileBucketCID,
});
if (!user) {

View File

@ -55,24 +55,11 @@ export default async (req, res) => {
const salt = await BCrypt.genSalt(rounds);
const hash = await Utilities.encryptPassword(req.body.data.password, salt);
const { textileKey, textileToken, textileThreadID, textileBucketCID } =
await Utilities.createBucket({});
if (!textileKey || !textileToken || !textileThreadID || !textileBucketCID) {
return res
.status(500)
.send({ decorator: "SERVER_CREATE_USER_BUCKET_INIT_FAILURE", error: true });
}
const user = await Data.createUser({
password: hash,
salt,
username: newUsername,
email: newEmail,
textileKey,
textileToken,
textileThreadID,
textileBucketCID,
});
if (!user) {

View File

@ -1,7 +1,4 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Social from "~/node_common/social";
import SearchManager from "~/node_common/managers/search";
import * as RequestUtilities from "~/node_common/request-utilities";
@ -24,25 +21,6 @@ export default async (req, res) => {
// NOTE(martina): delete all of their public and private files.
files = await Data.deleteFilesByUserId({ ownerId: id });
const defaultData = await Utilities.getBucket({ user });
// NOTE(jim): delete every bucket
try {
const roots = await defaultData.buckets.list();
for (let i = 0; i < roots.length; i++) {
await defaultData.buckets.remove(roots[i].key);
}
} catch (e) {
Social.sendTextileSlackMessage({
file: "/pages/api/users/delete.js",
user,
message: e.message,
code: e.code,
functionName: `b.remove`,
});
}
SearchManager.deleteUser(user);
// NOTE(jim): remove orphan

View File

@ -1,16 +1,9 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Strings from "~/common/strings";
import * as Validations from "~/common/validations";
import * as SlateManager from "~/node_common/managers/slate";
import * as Constants from "~/node_common/constants";
import JWT from "jsonwebtoken";
import { PrivateKey } from "@textile/hub";
import { Verification } from "~/components/core/Auth/components";
export default async (req, res) => {
if (!Strings.isEmpty(Environment.ALLOWED_HOST) && req.headers.host !== Environment.ALLOWED_HOST) {
return res.status(403).send({ decorator: "SERVER_MIGRATE_USER_NOT_ALLOWED", error: true });
@ -49,8 +42,8 @@ export default async (req, res) => {
return res.status(401).send({ decorator: "SERVER_MIGRATE_USER_INVALID_PIN", error: true });
}
const username = verification.username;
const email = verification.email;
const username = verification?.username;
const email = verification?.email;
const user = await Data.getUserByUsername({ username });
if (!user) {

View File

@ -2,10 +2,8 @@ import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Validations from "~/common/validations";
import * as Social from "~/node_common/social";
import * as ViewerManager from "~/node_common/managers/viewer";
import SearchManager from "~/node_common/managers/search";
import * as Logging from "~/common/logging";
import * as RequestUtilities from "~/node_common/request-utilities";
import BCrypt from "bcrypt";
@ -93,40 +91,5 @@ export default async (req, res) => {
ViewerManager.hydratePartial(id, { viewer: true });
}
if (req.body.data.type === "SAVE_DEFAULT_ARCHIVE_CONFIG") {
let b;
try {
b = await Utilities.getBucket({ user });
} catch (e) {
Logging.error(e);
Social.sendTextileSlackMessage({
file: "/pages/api/users/update.js",
user,
message: e.message,
code: e.code,
functionName: `Utilities.getBucket`,
});
return res.status(500).send({ decorator: "SERVER_NO_BUCKET_DATA", error: true });
}
try {
await b.buckets.setDefaultArchiveConfig(b.bucketKey, req.body.data.config);
} catch (e) {
Logging.error(e);
Social.sendTextileSlackMessage({
file: "/pages/api/users/update.js",
user,
message: e.message,
code: e.code,
functionName: `b.buckets.setDefaultArchiveConfig`,
});
return res
.status(500)
.send({ decorator: "SERVER_USER_UPDATE_DEFAULT_ARCHIVE_CONFIG", error: true });
}
}
return res.status(200).send({ decorator: "SERVER_USER_UPDATE" });
};