Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #73 from useaurora/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Renato Pozzi authored Jul 7, 2021
2 parents 58a9404 + 0e6ffc6 commit bacff5b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
21 changes: 15 additions & 6 deletions pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ const Login = () => {

const initialValues = { email: "", password: "" };

const handleSubmit = (values, { setSubmitting }) =>
client
.post("/v2/auth/login", values)
.then(() => router.push("/"))
.catch(() => setErrors(["Invalid credentials."]))
.finally(() => setSubmitting(false));
const handleSubmit = async (values, { setSubmitting }) => {
try {
const res = await client.post("/v2/auth/login", values);

if (res.data.response_type === "jwt") {
window.localStorage.setItem("aurora_jwt", res.data.access_token);
}

router.push("/");
} catch (err) {
setErrors(["Invalid credentials."]);
}

setSubmitting(false);
};

return (
<div className="min-h-screen bg-white dark:bg-black flex flex-col justify-center items-center">
Expand Down
6 changes: 6 additions & 0 deletions utils/__tests__/urls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ const { dropProtocol } = require("../urls");
describe("Testing Url dropProtocoling works", () => {
it("testing with correct protocols", () => {
expect(dropProtocol("https://google.com")).toBe("google.com");
expect(dropProtocol("https://www.google.com")).toBe("google.com");
expect(dropProtocol("www.google.com")).toBe("google.com");
expect(dropProtocol("http://facebook.com")).toBe("facebook.com");
expect(dropProtocol("http://www.facebook.com")).toBe("facebook.com");
expect(dropProtocol("www.facebook.com")).toBe("facebook.com");
expect(dropProtocol("ht://nosense.com")).toBe("nosense.com");
expect(dropProtocol("//nosense.com")).toBe("nosense.com");
});

it("testing with incorrect protocols", () => {
expect(dropProtocol("ht://nosense.com")).toBe("nosense.com");
expect(dropProtocol("ht://www.nosense.com")).toBe("nosense.com");
expect(dropProtocol("//nosense.com")).toBe("nosense.com");
expect(dropProtocol("//www.nosense.com")).toBe("nosense.com");
});

it("testing without syntax correct protocols", () => {
Expand Down
12 changes: 12 additions & 0 deletions utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@ const client = axios.create({
withCredentials: true,
});

client.interceptors.request.use(
(request) => {
if (localStorage.getItem("aurora_jwt") !== null) {
request.headers.common["Authorization"] = `Bearer ${localStorage.getItem("aurora_jwt")}`;
}
return request;
},
(err) => {
return Promise.reject(err);
}
);

module.exports = { client };
2 changes: 1 addition & 1 deletion utils/urls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const dropProtocol = (url) => url.replace(/(^\w+:|^)\/\//, "");
const dropProtocol = (url) => url.replace(/(^\w+:|^)\/\//, "").replace("www.", "");

module.exports = { dropProtocol };

0 comments on commit bacff5b

Please sign in to comment.