Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added username password front-end back-end and alignment #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"githubPullRequests.ignoredPullRequestBranches": ["master"]
}
53 changes: 53 additions & 0 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,62 @@ const transformUser = (
};
};

export const getUserMetadata = async (
userId: string
): Promise<{
firstName: string;
lastName: string;
}> => {
let response = await chain("query")({
auth_users: [
{
where: {
id: { _eq: userId },
},
},
{
id: true,
firstname: true,
lastname: true,
},
],
});
return {
firstName: response.auth_users[0].firstname || "",
lastName: response.auth_users[0].lastname || "",
};
};

export const updateUserMetadata = async (
userId: string,
firstName: string,
lastName: string
) => {
const response = await chain("mutation")({
update_auth_users: [
{
where: {
id: { _eq: userId },
},
_set: {
firstname: firstName,
lastname: lastName,
},
},
{
affected_rows: true,
},
],
});
};

/**
* Create a user
*/
export const createUser = async (
username: string,
firstName: string,
lastName: string,
blockchainPublicKeys: Array<{ blockchain: Blockchain; publicKey: string }>,
waitlistId?: string | null,
referrerId?: string
Expand Down Expand Up @@ -329,6 +380,8 @@ export const createUser = async (
{
object: {
username: username,
firstname: firstName,
lastname: lastName,
public_keys: {
data: blockchainPublicKeys.map((b) => ({
blockchain: b.blockchain,
Expand Down
23 changes: 22 additions & 1 deletion backend/native/backpack-api/src/routes/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
getUser,
getUserByPublicKeyAndChain,
getUserByUsername,
getUserMetadata,
getUsers,
getUsersByPrefix,
getUsersByPublicKeys,
getUsersMetadata,
updateUserAvatar,
updateUserMetadata,
} from "../../db/users";
import { getOrcreateXnftSecret } from "../../db/xnftSecrets";
import { logger } from "../../logger";
Expand Down Expand Up @@ -120,11 +122,28 @@ router.get("/jwt/xnft", extractUserId, async (req, res) => {
return res.json({ jwt: signedJwt });
});

router.get("/metadata", extractUserId, async (req, res) => {
const userId: string = req.id!;
const metadata = await getUserMetadata(userId);
res.json({
firstName: metadata.firstName,
lastName: metadata.lastName,
});
});

router.put("/metadata", extractUserId, async (req, res) => {
const userId: string = req.id!;
const firstName: string = req.body.firstName;
const lastName: string = req.body.lastName;
await updateUserMetadata(userId, firstName, lastName);
res.json({});
});

/**
* Create a new user.
*/
router.post("/", async (req, res) => {
const { username, waitlistId, blockchainPublicKeys } =
const { username, waitlistId, blockchainPublicKeys, firstName, lastName } =
CreateUserWithPublicKeys.parse(req.body);

// Validate all the signatures
Expand Down Expand Up @@ -182,6 +201,8 @@ router.post("/", async (req, res) => {

const user = await createUser(
username,
firstName,
lastName,
blockchainPublicKeys.map((b) => ({
...b,
// Cast blockchain to correct type
Expand Down
12 changes: 12 additions & 0 deletions backend/native/backpack-api/src/validation/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export const BaseCreateUser = z.object({
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
firstName: z
.string()
.regex(
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
lastName: z
.string()
.regex(
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
inviteCode: z
.string()
.regex(
Expand Down
1 change: 1 addition & 0 deletions backend/native/zeus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"graphql": "^16.8.1",
"tsc-alias": "^1.7.1",
"typescript": "~4.9.3"
},
Expand Down
14 changes: 14 additions & 0 deletions backend/native/zeus/src/zeus/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,10 @@ export const AllTypesProps: Record<string, any> = {
_or: "auth_users_bool_exp",
created_at: "timestamptz_comparison_exp",
dropzone_public_key: "auth_public_keys_bool_exp",
firstname: "String_comparison_exp",
id: "uuid_comparison_exp",
invitation: "auth_invitations_bool_exp",
lastname: "String_comparison_exp",
public_keys: "auth_public_keys_bool_exp",
public_keys_aggregate: "auth_public_keys_aggregate_bool_exp",
referred_users: "auth_users_bool_exp",
Expand All @@ -784,12 +786,16 @@ export const AllTypesProps: Record<string, any> = {
},
auth_users_max_order_by: {
created_at: "order_by",
firstname: "order_by",
id: "order_by",
lastname: "order_by",
username: "order_by",
},
auth_users_min_order_by: {
created_at: "order_by",
firstname: "order_by",
id: "order_by",
lastname: "order_by",
username: "order_by",
},
auth_users_obj_rel_insert_input: {
Expand All @@ -804,8 +810,10 @@ export const AllTypesProps: Record<string, any> = {
auth_users_order_by: {
created_at: "order_by",
dropzone_public_key_aggregate: "auth_public_keys_aggregate_order_by",
firstname: "order_by",
id: "order_by",
invitation: "auth_invitations_order_by",
lastname: "order_by",
public_keys_aggregate: "auth_public_keys_aggregate_order_by",
referred_users_aggregate: "auth_users_aggregate_order_by",
referrer: "auth_users_order_by",
Expand Down Expand Up @@ -2084,8 +2092,10 @@ export const ReturnTypes: Record<string, any> = {
auth_users: {
created_at: "timestamptz",
dropzone_public_key: "auth_public_keys",
firstname: "String",
id: "uuid",
invitation: "auth_invitations",
lastname: "String",
public_keys: "auth_public_keys",
public_keys_aggregate: "auth_public_keys_aggregate",
referred_users: "auth_users",
Expand All @@ -2104,12 +2114,16 @@ export const ReturnTypes: Record<string, any> = {
},
auth_users_max_fields: {
created_at: "timestamptz",
firstname: "String",
id: "uuid",
lastname: "String",
username: "citext",
},
auth_users_min_fields: {
created_at: "timestamptz",
firstname: "String",
id: "uuid",
lastname: "String",
username: "citext",
},
auth_users_mutation_response: {
Expand Down
Loading