Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected auth models #1583

Merged
merged 66 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
87a24b1
WIP: Auth entity
infomiho Nov 15, 2023
7749dec
Merge branch 'main' into auth-model-experiment
infomiho Nov 15, 2023
a7e3c14
Username and password working
infomiho Nov 15, 2023
bf77d11
Add support for email auth
infomiho Nov 15, 2023
238c3a8
Add support for Social auth
infomiho Nov 15, 2023
627ecf9
Add tasks to User
infomiho Nov 16, 2023
4259689
Update authentication providers and entities
infomiho Nov 24, 2023
20d4fd4
Email authentication. Test adding signup fields
infomiho Nov 24, 2023
33eb3aa
Migration with seed scripts
infomiho Nov 24, 2023
993e39d
Migrate Todo app
infomiho Nov 24, 2023
cf38191
Clenaup
infomiho Nov 27, 2023
9dfbd6c
Remove example app
infomiho Nov 27, 2023
4d0e3e4
Cleanup
infomiho Nov 27, 2023
a768c36
Updates tests
infomiho Nov 27, 2023
83ad555
Cleanup
infomiho Nov 27, 2023
8693c69
Fixes tests
infomiho Nov 28, 2023
43fb9f7
Merge branch 'main' into auth-model-experiment
infomiho Dec 12, 2023
e6f6a17
Use JSON based auth model
infomiho Dec 12, 2023
2714731
Refactor provider data serialization
infomiho Dec 12, 2023
872bca1
Updates typing of provider data
infomiho Dec 13, 2023
fd87def
Remove Prisma middleware. Fixes types
infomiho Dec 13, 2023
3ae0468
Cleanup
infomiho Dec 13, 2023
b5e0c05
Fixes double password hashing issue
infomiho Dec 13, 2023
315962f
Fixes headless test
infomiho Dec 13, 2023
95bda0a
Update e2e tests
infomiho Dec 13, 2023
efc2291
Cleanup
infomiho Dec 13, 2023
7fa0fe1
Merge branch 'main' into auth-model-experiment
infomiho Dec 14, 2023
21b0e77
Updates utils.ts. Updates websocket example app
infomiho Dec 14, 2023
f94f7fd
Update e2e tests
infomiho Dec 14, 2023
0a1d965
Update examples apps. Update server utils.ts
infomiho Dec 14, 2023
52f0881
PR comments
infomiho Dec 18, 2023
f982e6d
Updates e2e tests
infomiho Dec 18, 2023
48484c1
Add user ID helpers
infomiho Dec 18, 2023
6ba6a21
Fixes e2e tests
infomiho Dec 18, 2023
cf19e38
Improve naming and types
infomiho Dec 19, 2023
c5aee00
Updates e2e tests
infomiho Dec 19, 2023
a3cb241
Update examples/waspello/src/client/Navbar.jsx
infomiho Dec 19, 2023
b0b1a8b
PR comments
infomiho Dec 21, 2023
ce1c89b
PR comments
infomiho Dec 21, 2023
c3e46dc
Minor fixes. Rename local provider to username
infomiho Dec 22, 2023
c58ed9c
Updates e2e tests
infomiho Dec 22, 2023
2429673
Fixes frontend unit tests
infomiho Dec 22, 2023
d71d0f7
PR comments
infomiho Dec 22, 2023
8d27abb
Update e2e tests
infomiho Dec 22, 2023
d9690bb
Improve username handling in examples. Add getFirstProviderUserId
infomiho Dec 22, 2023
226e38b
Update e2e tests
infomiho Dec 22, 2023
9303dbc
Update seed script path
infomiho Dec 22, 2023
7ea4792
Add comment above PossibleProviderData
infomiho Dec 22, 2023
887ce20
Use UTC date for auth related timings
infomiho Dec 22, 2023
215bb86
Updates e2e tests
infomiho Dec 22, 2023
227a2f8
unverfiied email signup flow. foregin constraint error
infomiho Dec 23, 2023
1c53057
e2e tests
infomiho Dec 23, 2023
5daf665
Use token in email verification and password reset
infomiho Dec 23, 2023
4d1a863
e2e tests
infomiho Dec 23, 2023
dba9d28
Fix user creation and deletion errors
infomiho Dec 27, 2023
c313736
e2e tests
infomiho Dec 27, 2023
acf5d1f
PR comments
infomiho Dec 29, 2023
49966c0
PR comments
infomiho Jan 2, 2024
7c1b66e
Update e2e tests
infomiho Jan 2, 2024
04a9ee1
Extract the oauth handler into a separate function
infomiho Jan 2, 2024
d84dcc9
e2e tests
infomiho Jan 2, 2024
d4339a4
Update waspc/data/Generator/templates/server/src/auth/providers/email…
infomiho Jan 3, 2024
5077add
Apply suggestions from code review
infomiho Jan 3, 2024
9e4d7bb
Merge branch 'main' into auth-model-experiment
infomiho Jan 3, 2024
993eeac
PR comments
infomiho Jan 3, 2024
9b1185d
e2e tests
infomiho Jan 3, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- CreateTable
CREATE TABLE "Submission" (
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"github" TEXT NOT NULL,
"description" TEXT NOT NULL,
"twitter" TEXT,
"country" TEXT,
"website" TEXT,
"image" TEXT,
"approved" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Submission_pkey" PRIMARY KEY ("name")
);

-- CreateIndex
CREATE UNIQUE INDEX "Submission_name_key" ON "Submission"("name");

-- CreateIndex
CREATE UNIQUE INDEX "Submission_email_key" ON "Submission"("email");
3 changes: 3 additions & 0 deletions examples/hackathon-submissions/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
2 changes: 0 additions & 2 deletions examples/thoughts/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ psl=}

entity User {=psl
id Int @id @default(autoincrement())
username String @unique
password String

thoughts Thought[]
tags Tag[]
Expand Down
51 changes: 0 additions & 51 deletions examples/thoughts/migrations/20210513205603_/migration.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

81 changes: 81 additions & 0 deletions examples/thoughts/migrations/20231214130619_new_auth/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Thought" (
"id" SERIAL NOT NULL,
"textMarkdown" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" INTEGER NOT NULL,

CONSTRAINT "Thought_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tag" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"userId" INTEGER NOT NULL,

CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Auth" (
"id" TEXT NOT NULL,
"userId" INTEGER,

CONSTRAINT "Auth_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "AuthIdentity" (
"providerName" TEXT NOT NULL,
"providerUserId" TEXT NOT NULL,
"providerData" TEXT NOT NULL DEFAULT '{}',
"authId" TEXT NOT NULL,

CONSTRAINT "AuthIdentity_pkey" PRIMARY KEY ("providerName","providerUserId")
);

-- CreateTable
CREATE TABLE "_TagToThought" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Tag_name_userId_key" ON "Tag"("name", "userId");

-- CreateIndex
CREATE UNIQUE INDEX "Auth_userId_key" ON "Auth"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "_TagToThought_AB_unique" ON "_TagToThought"("A", "B");

-- CreateIndex
CREATE INDEX "_TagToThought_B_index" ON "_TagToThought"("B");

-- AddForeignKey
ALTER TABLE "Thought" ADD CONSTRAINT "Thought_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Auth" ADD CONSTRAINT "Auth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "AuthIdentity" ADD CONSTRAINT "AuthIdentity_authId_fkey" FOREIGN KEY ("authId") REFERENCES "Auth"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TagToThought" ADD CONSTRAINT "_TagToThought_A_fkey" FOREIGN KEY ("A") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TagToThought" ADD CONSTRAINT "_TagToThought_B_fkey" FOREIGN KEY ("B") REFERENCES "Thought"("id") ON DELETE CASCADE ON UPDATE CASCADE;
24 changes: 14 additions & 10 deletions examples/thoughts/src/client/TopNavbar.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React from 'react'
import React from "react";

import logout from '@wasp/auth/logout'
import logout from "@wasp/auth/logout";

import './TopNavbar.css'
import "./TopNavbar.css";

import { getUsername } from "@wasp/auth/user";

const TopNavbar = (props) => {
const user = props.user
const TopNavbar = ({ user }) => {
const username = getUsername(user);

return (
<div className="top-navbar">
{ user.username }
{username}
&nbsp;|&nbsp;
<button className="plain" onClick={logout}> logout </button>
<button className="plain" onClick={logout}>
{" "}
logout{" "}
</button>
</div>
)
}
);
};

export default TopNavbar
export default TopNavbar;
2 changes: 0 additions & 2 deletions examples/todo-typescript/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ app TodoTypescript {
// Then run `wasp db studio` to open Prisma Studio and view your db models
entity User {=psl
id Int @id @default(autoincrement())
username String @unique
password String
tasks Task[]
psl=}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

-- CreateTable
CREATE TABLE "Task" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"description" TEXT NOT NULL,
"isDone" BOOLEAN NOT NULL DEFAULT false,
"userId" INTEGER NOT NULL,
CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Auth" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" INTEGER,
CONSTRAINT "Auth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "AuthIdentity" (
"providerName" TEXT NOT NULL,
"providerUserId" TEXT NOT NULL,
"providerData" TEXT NOT NULL DEFAULT '{}',
"authId" TEXT NOT NULL,

PRIMARY KEY ("providerName", "providerUserId"),
CONSTRAINT "AuthIdentity_authId_fkey" FOREIGN KEY ("authId") REFERENCES "Auth" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "Auth_userId_key" ON "Auth"("userId");
6 changes: 4 additions & 2 deletions examples/todo-typescript/src/client/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import getTasks from "@wasp/queries/getTasks";
import createTask from "@wasp/actions/createTask";
import updateTask from "@wasp/actions/updateTask";
import deleteTasks from "@wasp/actions/deleteTasks";
import type { Task, User } from "@wasp/entities";
import type { Task } from "@wasp/entities";
import type { User } from "@wasp/auth/types";
import { getUsername } from "@wasp/auth/user";

export const MainPage = ({ user }: { user: User }) => {
const { data: tasks, isLoading, error } = useQuery(getTasks);
Expand All @@ -24,7 +26,7 @@ export const MainPage = ({ user }: { user: User }) => {
<img src={waspLogo} alt="wasp logo" />
{user && (
<h1>
{user.username}
{getUsername(user)}
{`'s tasks :)`}
</h1>
)}
Expand Down
2 changes: 0 additions & 2 deletions examples/tutorials/TodoApp/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ page LoginPage {

entity User {=psl
id Int @id @default(autoincrement())
username String @unique
password String
tasks Task[]
psl=}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading