Skip to content

Commit

Permalink
Injected auth models (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho authored Jan 3, 2024
1 parent e41fc57 commit 633e25c
Show file tree
Hide file tree
Showing 161 changed files with 2,936 additions and 1,867 deletions.
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

0 comments on commit 633e25c

Please sign in to comment.