-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwelcome.tsx
50 lines (40 loc) · 1.13 KB
/
welcome.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as React from "react";
import Head from "next/head";
import { DefaultUser } from "@/backend/functions";
import { getSession } from "next-auth/react";
import { GetServerSideProps } from "next";
interface UserDashboardProps {
user: DefaultUser;
}
export default function Welcome({ user }: UserDashboardProps) {
React.useEffect(() => {
localStorage.setItem("user", JSON.stringify(user));
if (new Date().getUTCMilliseconds() - new Date(user.createdAt!).getTime() <= 3000) {
window.location.href = '/onboarding'
} else {
window.location.href = '/'
}
})
return (
<>
<Head>
<title>Welcome | COMETLABS</title>
</Head>
</>
);
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getSession(context);
if (!!session) {
const user: DefaultUser = session.user as DefaultUser;
return {
props: { user },
};
}
return {
redirect: {
permanent: false,
destination: "/signin",
},
};
};