Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

fix: stats page increment #5628

Merged
merged 2 commits into from
Mar 24, 2023
Merged
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
29 changes: 11 additions & 18 deletions pages/account/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import {
ResponsiveContainer,
} from "recharts";

import logger from "../../config/logger";
import { getUserApi } from "../api/users/[username]";
import logger from "@config/logger";
import Alert from "@components/Alert";
import Page from "@components/Page";
import PageHead from "@components/PageHead";
import { abbreviateNumber } from "../../services/utils/abbreviateNumbers";
import BasicCards from "../../components/statistics/BasicCards";
import { abbreviateNumber } from "@services/utils/abbreviateNumbers";
import BasicCards from "@components/statistics/BasicCards";

export async function getServerSideProps(context) {
const session = await unstable_getServerSession(
context.req,
context.res,
authOptions
);
const { req, res } = context;
const session = await unstable_getServerSession(req, res, authOptions);

if (!session) {
return {
Expand All @@ -34,18 +32,13 @@ export async function getServerSideProps(context) {
};
}
const username = session.username;

let profile = {};
try {
const resUser = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL}/api/users/${username}`
const { status, profile } = await getUserApi(req, res, username);
if (status !== 200) {
logger.error(
profile.error,
`profile loading failed for username: ${username}`
);
profile = await resUser.json();
} catch (e) {
logger.error(e, `profile loading failed for username: ${username}`);
}

if (!profile.username) {
return {
redirect: {
destination: "/account/no-profile",
Expand Down