Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion app/models/note.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function createNote({
const { data, error } = await supabase
.from("notes")
.insert([{ title, body, profile_id: userId }])
.select()
.single();

if (!error) {
Expand All @@ -40,7 +41,7 @@ export async function deleteNote({
}: Pick<Note, "id"> & { userId: User["id"] }) {
const { error } = await supabase
.from("notes")
.delete({ returning: "minimal" })
.delete()
.match({ id, profile_id: userId });

if (!error) {
Expand Down
9 changes: 4 additions & 5 deletions app/models/user.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import bcrypt from "bcryptjs";
import { createClient } from "@supabase/supabase-js";
import invariant from "tiny-invariant";

Expand All @@ -20,13 +19,13 @@ invariant(
export const supabase = createClient(supabaseUrl, supabaseAnonKey);

export async function createUser(email: string, password: string) {
const { user } = await supabase.auth.signUp({
const { data } = await supabase.auth.signUp({
email,
password,
});

// get the user profile after created
const profile = await getProfileByEmail(user?.email);
const profile = await getProfileByEmail(data.user?.email);

return profile;
}
Expand Down Expand Up @@ -54,13 +53,13 @@ export async function getProfileByEmail(email?: string) {
}

export async function verifyLogin(email: string, password: string) {
const { user, error } = await supabase.auth.signIn({
const { data, error } = await supabase.auth.signInWithPassword({
email,
password,
});

if (error) return undefined;
const profile = await getProfileByEmail(user?.email);
const profile = await getProfileByEmail(data.user?.email);

return profile;
}
7 changes: 7 additions & 0 deletions app/routes/join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export const action: ActionFunction = async ({ request }) => {

const user = await createUser(email, password);

if (!user) {
return json<ActionData>(
{ errors: { email: "Failed to create user." } },
{ status: 500 }
);
}

return createUserSession({
request,
userId: user.id,
Expand Down
124 changes: 63 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@remix-run/netlify": "^1.6.8",
"@remix-run/node": "^1.6.8",
"@remix-run/react": "^1.6.8",
"@supabase/supabase-js": "^1.31.1",
"@supabase/supabase-js": "^2.1.1",
"@testing-library/cypress": "^8.0.3",
"bcryptjs": "^2.4.3",
"cypress": "^10.4.0",
Expand Down