Skip to content

Commit

Permalink
remove ant design
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 26, 2023
1 parent 54998b1 commit ddb196a
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 228 deletions.
42 changes: 38 additions & 4 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export function authRoutes(fastify: FastifyInstance) {
throw new Error("Password is not valid");
}

var b64string = "TOMATOSOUP";
var buf = new Buffer(b64string, "base64"); // Ta-da
var b64string = process.env.SECRET;
var buf = new Buffer(b64string!, "base64"); // Ta-da

let token = jwt.sign(
{
data: { id: user!.id },
},
buf,
{ expiresIn: "1d" }
{ expiresIn: "7d" }
);

await prisma.session.create({
Expand Down Expand Up @@ -246,7 +246,41 @@ export function authRoutes(fastify: FastifyInstance) {
fastify.put(
"/api/v1/auth/profile",
async (request: FastifyRequest, reply: FastifyReply) => {
//
const bearer = request.headers.authorization!.split(" ")[1];

//checks if token is valid and returns valid token
const token = checkToken(bearer);

if (token) {
let session = await prisma.session.findUnique({
where: {
sessionToken: bearer,
},
});

const { name, email, language } = request.body as {
name: string;
email: string;
language: string;
};

let user = await prisma.user.update({
where: { id: session?.userId },
data: {
name: name,
email: email,
language: language,
},
});

reply.send({
user,
});
} else {
reply.send({
sucess: false,
});
}
}
);

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/lib/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import jwt from "jsonwebtoken";
export function checkToken(token: string) {
const bearer = token;

var b64string = "TOMATOSOUP";
var buf = new Buffer(b64string, "base64"); // Ta-da
var b64string = process.env.SECRET;
var buf = new Buffer(b64string!, "base64"); // Ta-da

const verified = jwt.verify(bearer, buf);

Expand Down
20 changes: 11 additions & 9 deletions apps/client/components/ListTodo/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { TrashIcon } from "@heroicons/react/20/solid";
import { Pagination } from "antd";
import { getCookie } from "cookies-next";
import { useState } from "react";
import { useQuery } from "react-query";

async function getTodos(token) {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/todos/all`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
});
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/todos/all`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return res.json();
}

Expand Down Expand Up @@ -125,13 +127,13 @@ export default function ListTodo() {
<p>None Found</p>
)}
</div>
<div className={data.todos && data.todos.length > 12 ? "mt-4" : "hidden"}>
{/* <div className={data.todos && data.todos.length > 12 ? "mt-4" : "hidden"}>
<Pagination
defaultCurrent={1}
total={12}
onChange={handleChange}
/>
</div>
</div> */}
</div>
)}
</div>
Expand Down
54 changes: 31 additions & 23 deletions apps/client/components/ResetPassword/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
import { Dialog, Transition } from "@headlessui/react";
import { XMarkIcon } from "@heroicons/react/24/outline";
import { message } from "antd";
import React, { Fragment, useState } from "react";

export default function ResetPassword({ user }) {
const [open, setOpen] = useState(false);
const [password, setPassword] = useState("");
const [check, setCheck] = useState("");

const success = () => {
message.success("Password updated");
};

const fail = (f) => {
message.error(`${f}`);
};

const postData = async () => {
const id = user.id;
if (check === password && password.length > 0) {
await fetch(`/api/v1/admin/user/resetpassword`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
password,
id,
}),
})
await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/reset-password`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
body: JSON.stringify({
password,
}),
}
)
.then((res) => res.json())
.then((res) => {
if (res.failed === false) {
success();
notifications.show({
title: "Success",
message: `Password updated :)`,
color: "green",
autoClose: 5000,
});
} else {
fail(res.message);
notifications.show({
title: "Error",
message: `Error: ${res.message}`,
color: "red",
autoClose: 5000,
});
}
});
} else {
fail("Passwords are not the same or empty");
notifications.show({
title: "Error",
message: `Error: passwords do not match`,
color: "red",
autoClose: 5000,
});
}
};

Expand Down
Loading

0 comments on commit ddb196a

Please sign in to comment.