Updates
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import Main from "@/src/components/pages/auth/login";
|
||||
import Layout from "@/src/layouts/login";
|
||||
import userAuth from "@/src/utils/user-auth";
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import { GetServerSideProps } from "next";
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
@@ -8,3 +11,31 @@ export default function LoginPage() {
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const users = await NSQLite.select({ table: "users" });
|
||||
|
||||
if (!users.payload?.[0]) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/auth/signup`,
|
||||
statusCode: 307,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const { singleRes: user } = await userAuth({ req: ctx.req });
|
||||
|
||||
if (user?.logged_in_status) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/admin`,
|
||||
statusCode: 307,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import Main from "@/src/components/pages/auth/signup";
|
||||
import Layout from "@/src/layouts/login";
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import { GetServerSideProps } from "next";
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<Layout>
|
||||
<Main />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const users = await NSQLite.select({ table: "users" });
|
||||
|
||||
if (users.payload?.[0]) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/auth/login`,
|
||||
statusCode: 307,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user