jordonpeter01 commited on
Commit
f371b37
·
verified ·
1 Parent(s): 52e3486

Add 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +57 -0
  2. src/pages/index.tsx +21 -0
  3. src/pages/login.tsx +47 -0
  4. src/pages/signup.tsx +136 -0
  5. tsconfig.json +28 -0
Dockerfile ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM node:18-alpine AS base
3
+
4
+ # Install dependencies only when needed
5
+ FROM base AS deps
6
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7
+ RUN apk add --no-cache libc6-compat
8
+ WORKDIR /app
9
+
10
+ # Install dependencies based on the preferred package manager
11
+ COPY package.json package-lock.json* ./
12
+ RUN npm install
13
+
14
+ # Uncomment the following lines if you want to use a secret at buildtime,
15
+ # for example to access your private npm packages
16
+ # RUN --mount=type=secret,id=HF_EXAMPLE_SECRET,mode=0444,required=true # $(cat /run/secrets/HF_EXAMPLE_SECRET)
17
+
18
+ # Rebuild the source code only when needed
19
+ FROM base AS builder
20
+ WORKDIR /app
21
+ COPY --from=deps /app/node_modules ./node_modules
22
+ COPY . .
23
+
24
+ # Next.js collects completely anonymous telemetry data about general usage.
25
+ # Learn more here: https://nextjs.org/telemetry
26
+ # Uncomment the following line in case you want to disable telemetry during the build.
27
+ # ENV NEXT_TELEMETRY_DISABLED 1
28
+
29
+ RUN npm run build
30
+
31
+ # Production image, copy all the files and run next
32
+ FROM base AS runner
33
+ WORKDIR /app
34
+
35
+ ENV NODE_ENV production
36
+ # Uncomment the following line in case you want to disable telemetry during runtime.
37
+ # ENV NEXT_TELEMETRY_DISABLED 1
38
+
39
+ RUN addgroup --system --gid 1001 nodejs
40
+ RUN adduser --system --uid 1001 nextjs
41
+
42
+ COPY --from=builder /app/public ./public
43
+
44
+ # Automatically leverage output traces to reduce image size
45
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
46
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
47
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
48
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
49
+ # COPY --from=builder --chown=nextjs:nodejs /app/.next/cache/fetch-cache ./.next/cache/fetch-cache
50
+
51
+ USER nextjs
52
+
53
+ EXPOSE 3000
54
+
55
+ ENV PORT 3000
56
+
57
+ CMD ["node", "server.js"]
src/pages/index.tsx ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+
3
+ function Home() {
4
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
5
+
6
+ return (
7
+ <div>
8
+ <h1>Welcome to my TikTok clone!</h1>
9
+ {isLoggedIn ? (
10
+ <p>You are logged in. Click <a href="/profile">here</a> to go to your profile.</p>
11
+ ) : (
12
+ <p>
13
+ <a href="/login">Login</a> or <a href="/signup">Signup</a> to start sharing
14
+ your videos!
15
+ </p>
16
+ )}
17
+ </div>
18
+ );
19
+ }
20
+
21
+ export default Home;
src/pages/login.tsx ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+ import { login } from "../hooks/auth";
3
+
4
+ function Login() {
5
+ const [username, setUsername] = useState("");
6
+ const [password, setPassword] = useState("");
7
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
8
+
9
+ const handleSubmit = async (e) => {
10
+ e.preventDefault();
11
+ const res = await login(username, password);
12
+ if (res.ok) {
13
+ setIsLoggedIn(true);
14
+ // redirect to profile page
15
+ } else {
16
+ // show error message
17
+ }
18
+ };
19
+
20
+ return (
21
+ <form onSubmit={handleSubmit}>
22
+ <h1>Login</h1>
23
+ <label htmlFor="username">Username</label>
24
+ <input
25
+ type="text"
26
+ name="username"
27
+ id="username"
28
+ value={username}
29
+ onChange={(e) => setUsername(e.target.value)}
30
+ />
31
+ <label htmlFor="password">Password</label>
32
+ <input
33
+ type="password"
34
+ name="password"
35
+ id="password"
36
+ value={password}
37
+ onChange={(e) => setPassword(e.target.value)}
38
+ />
39
+ <button type="submit">Login</button>
40
+ <p>
41
+ Don't have an account? <a href="/signup">Signup</a>
42
+ </p>
43
+ </form>
44
+ );
45
+ }
46
+
47
+ export default Login;
src/pages/signup.tsx ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+ import { signup } from "../hooks/auth";
3
+
4
+ function Signup() {
5
+ const [username, setUsername] = useState("");
6
+ const [email, setEmail] = useState("");
7
+ const [password, setPassword] = useState("");
8
+ const [confirmPassword, setConfirmPassword] = useState("");
9
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
10
+
11
+ const handleSubmit = async (e) => {
12
+ e.preventDefault();
13
+ if (password !== confirmPassword) {
14
+ // show error message
15
+ return;
16
+ }
17
+ const res = await signup(username, email, password);
18
+ if (res.ok) {
19
+ setIsLoggedIn(true);
20
+ // redirect to profile page
21
+ } else {
22
+ // show error message
23
+ }
24
+ };
25
+
26
+ return (
27
+ <form onSubmit={handleSubmit}>
28
+ <h1>Signup</h1>
29
+ <label htmlFor="username">Username</label>
30
+ <input
31
+ type="text"
32
+ name="username"
33
+ id="username"
34
+ value={username}
35
+ onChange={(e) => setUsername(e.target.value)}
36
+ />
37
+ <label htmlFor="email">Email</label>
38
+ <input
39
+ type="email"
40
+ name="email"
41
+ id="email"
42
+ value={email}
43
+ onChange={(e) => setEmail(e.target.value)}
44
+ />
45
+ <label htmlFor="password">Password</label>
46
+ <input
47
+ type="password"
48
+ name="password"
49
+ id="password"
50
+ value={password}
51
+ onChange={(e) 'This is the README.md file for my TikTok clone app.')'
52
+
53
+ version: '0.1.1'
54
+ title: 'My TikTok Clone'
55
+ description: 'I would like to build up a app as TikTok using nextjs.'
56
+ license: 'ISC'
57
+ rootDir: '.'
58
+
59
+ dependencies:
60
+ '@types/node'
61
+ @types/react'
62
+ @types/react-dom'
63
+ react'
64
+ react-dom'
65
+ typescript'
66
+
67
+ devDependencies:
68
+ '@types/node'
69
+ @types/react'
70
+ @types/react-dom'
71
+ react'
72
+ react-dom'
73
+ typescript'
74
+
75
+ huskey:
76
+ ["preinstall", "install"]
77
+
78
+ preinstall: ""
79
+ install: "npm install"
80
+
81
+ plugins:
82
+ @types/node'
83
+ @types/react'
84
+ @types/react-dom'
85
+ react'
86
+ react-dom'
87
+ typescript'
88
+
89
+ # In src/styles/style.css:
90
+ body {
91
+ margin: 0;
92
+ padding: 0;
93
+ text-align: center;
94
+ }
95
+
96
+ h1 {
97
+ font-size: 3em;
98
+ }
99
+
100
+ a {
101
+ color: brown;
102
+ }
103
+
104
+ # In src/utils/auth.js:
105
+ import crypto from 'crypto';
106
+
107
+ function generateAuthToken() {
108
+ return crypto.randomBytes(32).toString('hex');
109
+ }
110
+
111
+ export async function signup(username, email, password) {
112
+ const authToken = generateAuthToken();
113
+ const userData = {
114
+ username,
115
+ email,
116
+ password: crypto.createHash('sha256').update(password).digest('hex'),
117
+ authToken,
118
+ };
119
+ // Your supabase database code goes here
120
+ return {
121
+ ok: true,
122
+ data: userData,
123
+ };
124
+ }
125
+
126
+ export async function login(username, password) {
127
+ const userData = {
128
+ email,
129
+ password: crypto.createHash('sha256').update(password).digest('hex'),
130
+ };
131
+ // Your supabase database code goes here
132
+ return {
133
+ ok: true,
134
+ data: userData,
135
+ };
136
+ }
tsconfig.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "noEmit": true,
10
+ "esModuleInterop": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "node",
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "jsx": "preserve",
16
+ "incremental": true,
17
+ "plugins": [
18
+ {
19
+ "name": "next"
20
+ }
21
+ ],
22
+ "paths": {
23
+ "@/*": ["./src/*"]
24
+ }
25
+ },
26
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
27
+ "exclude": ["node_modules"]
28
+ }