Skip to content

Commit

Permalink
fix: Username casing (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefKai authored Jan 28, 2021
1 parent 7dda631 commit 1256a33
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/users/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NowRequest, NowResponse } from "@vercel/node";
import { toChecksumAddress } from "ethereumjs-util";
import { getModel } from "../../utils/mongo";

export default async (req: NowRequest, res: NowResponse): Promise<NowResponse | void> => {
Expand All @@ -16,7 +17,7 @@ export default async (req: NowRequest, res: NowResponse): Promise<NowResponse |
}

return res.status(200).json({
address: user.address,
address: toChecksumAddress(user.address),
username: user.username,
created_at: user.created_at,
updated_at: user.updated_at,
Expand Down
1 change: 1 addition & 0 deletions api/users/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async (req: NowRequest, res: NowResponse): Promise<NowResponse |
const user = await new userModel({
address: address.toLowerCase(),
username,
slug: username.toLowerCase(),
created_at: Date.now(),
updated_at: null,
}).save();
Expand Down
2 changes: 1 addition & 1 deletion utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const isValid = async (username: string): Promise<{ valid: boolean; messa

// Cannot have the same username as another user (Case insensitive)
const userModel = await getModel("User");
if (await userModel.exists({ username })) {
if (await userModel.exists({ slug: username.toLowerCase() })) {
return {
valid: false,
message: "Username taken",
Expand Down
4 changes: 4 additions & 0 deletions utils/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export const userSchema: Schema = new Schema(
},
required: true,
},
slug: {
type: String,
required: true,
},
created_at: {
type: Date,
default: Date.now,
Expand Down

1 comment on commit 1256a33

@vercel
Copy link

@vercel vercel bot commented on 1256a33 Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.