[resumes][fix] fix file upload failure

pull/321/head
Keane Chan 3 years ago
parent bc96643f04
commit 46f738fe02
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -8,7 +8,3 @@ NEXTAUTH_URL=http://localhost:3000
# Next Auth GitHub Provider # Next Auth GitHub Provider
GITHUB_CLIENT_ID=a5164b1943b5413ff2f5 GITHUB_CLIENT_ID=a5164b1943b5413ff2f5
GITHUB_CLIENT_SECRET= GITHUB_CLIENT_SECRET=
# Supabase
SUPABASE_URL=
SUPABASE_ANON_KEY=

@ -0,0 +1,3 @@
# Supabase
SUPABASE_URL=
SUPABASE_ANON_KEY=

@ -32,6 +32,7 @@
"react-pdf": "^5.7.2", "react-pdf": "^5.7.2",
"react-query": "^3.39.2", "react-query": "^3.39.2",
"superjson": "^1.10.0", "superjson": "^1.10.0",
"uuid": "^9.0.0",
"zod": "^3.18.0" "zod": "^3.18.0"
}, },
"devDependencies": { "devDependencies": {
@ -41,6 +42,7 @@
"@types/react": "^18.0.21", "@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/react-pdf": "^5.7.2", "@types/react-pdf": "^5.7.2",
"@types/uuid": "^8.3.4",
"autoprefixer": "^10.4.12", "autoprefixer": "^10.4.12",
"postcss": "^8.4.16", "postcss": "^8.4.16",
"prettier-plugin-tailwindcss": "^0.1.13", "prettier-plugin-tailwindcss": "^0.1.13",

@ -12,8 +12,6 @@ export const serverSchema = z.object({
NEXTAUTH_SECRET: z.string(), NEXTAUTH_SECRET: z.string(),
NEXTAUTH_URL: z.string().url(), NEXTAUTH_URL: z.string().url(),
NODE_ENV: z.enum(['development', 'test', 'production']), NODE_ENV: z.enum(['development', 'test', 'production']),
SUPABASE_ANON_KEY: z.string(),
SUPABASE_URL: z.string(),
}); });
/** /**
@ -22,7 +20,8 @@ export const serverSchema = z.object({
* To expose them to the client, prefix them with `NEXT_PUBLIC_`. * To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/ */
export const clientSchema = z.object({ export const clientSchema = z.object({
// NEXT_PUBLIC_BAR: z.string(), NEXT_PUBLIC_SUPABASE_ANON_KEY: z.string(),
NEXT_PUBLIC_SUPABASE_URL: z.string().url(),
}); });
/** /**
@ -33,4 +32,6 @@ export const clientSchema = z.object({
*/ */
export const clientEnv = { export const clientEnv = {
// NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR, // NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR,
NEXT_PUBLIC_SUPABASE_ANON_KEY: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
NEXT_PUBLIC_SUPABASE_URL: process.env.NEXT_PUBLIC_SUPABASE_URL,
}; };

@ -4,6 +4,7 @@ import { useRouter } from 'next/router';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import type { SubmitHandler } from 'react-hook-form'; import type { SubmitHandler } from 'react-hook-form';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { v4 as uuidv4 } from 'uuid';
import { PaperClipIcon } from '@heroicons/react/24/outline'; import { PaperClipIcon } from '@heroicons/react/24/outline';
import { Button, Select, TextArea, TextInput } from '@tih/ui'; import { Button, Select, TextArea, TextInput } from '@tih/ui';
@ -51,12 +52,11 @@ export default function SubmitResumeForm() {
const onSubmit: SubmitHandler<IFormInput> = async (data) => { const onSubmit: SubmitHandler<IFormInput> = async (data) => {
if (resumeFile == null) { if (resumeFile == null) {
// TODO: Handle error
return; return;
} }
// TODO: Generate unique URL
const url = resumeFile.name;
// Prefix with uuid so that it is always unique
const url = `${uuidv4()}-${resumeFile.name}`;
const { error } = await supabase.storage const { error } = await supabase.storage
.from('resumes') .from('resumes')
.upload(url, resumeFile); .upload(url, resumeFile);

@ -1,8 +1,8 @@
import { createClient } from '@supabase/supabase-js'; import { createClient } from '@supabase/supabase-js';
import { env } from '~/env/server.mjs'; import { env } from '~/env/client.mjs';
const supabaseUrl = env.SUPABASE_URL; const supabaseUrl = env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = env.SUPABASE_ANON_KEY; const supabaseAnonKey = env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey); export const supabase = createClient(supabaseUrl, supabaseAnonKey);

@ -3688,6 +3688,11 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d" resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ== integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==
"@types/uuid@^8.3.4":
version "8.3.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==
"@types/webpack-env@^1.16.0": "@types/webpack-env@^1.16.0":
version "1.18.0" version "1.18.0"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.0.tgz#ed6ecaa8e5ed5dfe8b2b3d00181702c9925f13fb" resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.0.tgz#ed6ecaa8e5ed5dfe8b2b3d00181702c9925f13fb"
@ -14565,6 +14570,11 @@ uuid@^8.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==
v8-compile-cache-lib@^3.0.1: v8-compile-cache-lib@^3.0.1:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"

Loading…
Cancel
Save