Skip to content

Commit

Permalink
Merge pull request #60 from RizkyRajitha/dev
Browse files Browse the repository at this point in the history
Hotfix v0.5.1
  • Loading branch information
RizkyRajitha authored Nov 30, 2021
2 parents d7e3e4e + f00efe6 commit 5e01d5c
Show file tree
Hide file tree
Showing 19 changed files with 1,329 additions and 5,670 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// diabled optimizeForSpeed becasue styled-jsx style not found error wehn updating styles
// diabled optimiuzeForSpeed becasue styled-jsx style not fond error wehn updating styles
// framework.cb05d56be993eb6b088a.js:1 DOMException: Failed to execute 'insertRule' on 'CSSStyleSheet': Failed to insert the rule.
//https://github.com/vercel/styled-jsx/issues/295
"presets": [["next/babel", { "styled-jsx": { "optimizeForSpeed": false } }]]
Expand Down
109 changes: 109 additions & 0 deletions .github/workflows/browsertesting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Browser-Testing

on: [push, pull_request]

jobs:
Browser-Testing:
runs-on: ubuntu-latest
# Service containers to run with `runner-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: install puppeteer libraries
run: |
sudo apt-get update
sudo apt-get install -y libgbm1
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: "node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm install

- name: Install puppeteer
run: npm install puppeteer

- name: Migrate database
run: npm run prismamigrateprod
env:
NODE_ENV: production
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

- name: Seed database
run: npm run seed
env:
NODE_ENV: production
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"

- name: Run browser testing script
id: browser-testing
env:
HASHSALT: 123
# NODE_ENV: production
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }}
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }}
run: |
chmod +x run-browser-testing.sh
./run-browser-testing.sh
- name: Use the value
id: step_two
run: |
echo "${{ env.commentBody }}"
- name: Add comment
uses: actions/github-script@v5
env:
SHA: ${{ github.sha }}
commentBody: ${{ env.commentBody }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let buffercommentBody = process.env.commentBody
let utf8commentBody = new Buffer.from(buffercommentBody, "base64").toString("utf8");
console.log(utf8commentBody);
github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: process.env.SHA,
body: utf8commentBody
})
2 changes: 1 addition & 1 deletion components/footerform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FontForm = ({ data, update, loading }) => {
formState: { errors },
} = useForm({ defaultValues: data });

console.log(data);
// console.log(data);

return (
<>
Expand Down
31 changes: 2 additions & 29 deletions components/formwrapper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { useRouter } from "next/router";
import { useState, useEffect } from "react";
import { ToastContainer, toast } from "react-toastify";

// importing hook useSWR from package swr
// import useSWR from "swr";

import styles from "../styles/formwrapper.module.css";

import ColorForm from "./colorform";
Expand Down Expand Up @@ -39,26 +35,11 @@ function Formwrapper({ pageData, updatedPageData }) {
});
}, [activeForm]);

// asynchronous function to fetch data to save page data and update page
// const savePageDataFetcher = async ([url, data]) =>
// await fetch(url, {
// method: "POST",
// body: JSON.stringify(data),
// headers: { "Content-Type": "application/json" },
// }).then((res) => res.json());

// savePageData was previously asynchronous
const savePageData = async (data) => {
setloading(true);
try {
// const { res } = useSWR(
// [`${endpoint}/api/updatepagedata`, data],
// savePageDataFetcher
// );
/*
the following piece of code has been replaced with the implementation of useSWR hook above

*/
let res = await fetch(`${endpoint}/api/updatepagedata`, {
method: "POST",
body: JSON.stringify(data),
Expand Down Expand Up @@ -93,21 +74,13 @@ function Formwrapper({ pageData, updatedPageData }) {
setloading(false);
};

// asynchronous function to fetch logout data
// const logOutFetcher = async (url) =>
// await fetch(url).then((res) => res.json());

// the logout function was previously asynchronous
const logout = async () => {
try {
// const { res } = useSWR(`${endpoint}/api/user/logout`, logOutFetcher);
/*
the following piece of code has been replaced with the implementation of useSWR hook above
*/

let res = await fetch(`${endpoint}/api/user/logout`).then((res) =>
res.json()
);
console.log(res);
// console.log(res);

if (res.success) {
router.push("/admin");
Expand Down
6 changes: 3 additions & 3 deletions components/linksform.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const LinksForm = ({ pagedataid }) => {
headers: { "Content-Type": "application/json" },
}).then((res) => res.json());

console.log(res);
// console.log(res);

if (!res.success) {
toast.error(`Error ${res.message}`, { autoClose: 5000 });
Expand Down Expand Up @@ -207,7 +207,7 @@ const LinksForm = ({ pagedataid }) => {
}
});

console.log(data);
// console.log(data);

let confirm = await Swal.fire({
title: "Apply common settings",
Expand All @@ -232,7 +232,7 @@ const LinksForm = ({ pagedataid }) => {
headers: { "Content-Type": "application/json" },
}).then((res) => res.json());

console.log(res);
// console.log(res);

if (!res.success) {
toast.error(`Error ${res.message}`, { autoClose: 5000 });
Expand Down
4 changes: 2 additions & 2 deletions components/passwordchangeform.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const PasswordChangeForm = () => {
password.current = watch("newPassword", "");

const updatePassword = async (data) => {
console.log(data);
// console.log(data);
setloading(true);

try {
Expand Down Expand Up @@ -57,7 +57,7 @@ const PasswordChangeForm = () => {
let res = await fetch(`${endpoint}/api/user/logout`).then((res) =>
res.json()
);
console.log(res);
// console.log(res);

if (res.success) {
router.push("/admin");
Expand Down
2 changes: 1 addition & 1 deletion components/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function Toast({ message, type, toaster }) {
const [msg, setmsg] = useState(message);

useEffect(() => {
console.log(message);
// console.log(message);

toaster(showError);

Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- "3000:3000"
environment:
DATABASE_URL: "postgres://linkin:linkin123@db:5432/linkin"
HASHSALT: "123" # random secret key
HASHSALT: "1234" # random secret key
NODE_ENV: "production"
depends_on:
- db
Expand All @@ -34,7 +34,6 @@ services:
POSTGRES_USER: "linkin"
POSTGRES_PASSWORD: "linkin123"
volumes:
# - ./scripts/db-migrate.sql:/docker-entrypoint-initdb.d/db-migrate.sql
- linkin-data:/var/lib/postgresql/data
volumes:
linkin-data:
2 changes: 1 addition & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const HASHSALT = process.env.HASHSALT;
export function createSecureToken(payload) {
let jwttoken = JWT.sign(payload, HASHSALT);
let encryttedToken = JWE.encrypt(jwttoken, HASHSALT);
console.log(encryttedToken);
// console.log(encryttedToken);
return encryttedToken;
}

Expand Down
26 changes: 19 additions & 7 deletions middleware/middleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import Cors from "cors";

import { parse } from "cookie";
import { parseSecureToken } from "../lib/crypto";

Expand Down Expand Up @@ -46,9 +44,15 @@ export function jwtAuth(req, res, next) {
export function cookieValidate(req, res) {
let cookie = req.headers?.cookie;

// console.log("dashboard cookie");

if (!cookie) {
res.setHeader("location", "/admin");
res.statusCode = 302;
res.writeHead(302, {
location: "/admin",
"Content-Type": "text/html",
});
// res.setHeader("location", "/admin");
// res.statusCode = 302;
res.end();
return new Error("cookie invalid");
}
Expand All @@ -58,7 +62,11 @@ export function cookieValidate(req, res) {
let decodedToken = parseSecureToken(token);

if (!decodedToken) {
res.setHeader("location", "/admin");
res.writeHead(302, {
location: "/admin",
"Content-Type": "text/html",
});
// res.setHeader("location", "/admin");
res.statusCode = 302;
res.end();
return new Error("cookie invalid");
Expand All @@ -75,8 +83,12 @@ export function cookieValidateLogin(req, res) {
let decodedToken = parseSecureToken(token);

if (decodedToken) {
res.setHeader("location", "/dashboard");
res.statusCode = 302;
res.writeHead(302, {
location: "/dashboard",
"Content-Type": "text/html",
});
// res.setHeader("location", "/dashboard");
// res.statusCode = 302;
res.end();
}
}
Loading

2 comments on commit 5e01d5c

@vercel
Copy link

@vercel vercel bot commented on 5e01d5c Nov 30, 2021

Choose a reason for hiding this comment

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

Screenshots

Dashboard 1920X1080


screenshot-Dashboard  1920X1080

Index 1920X1080


screenshot-Index  1920X1080

Index iphone 12|13 390X844


screenshot-Index iphone 12|13 390X844

Please sign in to comment.