Skip to content

Commit

Permalink
Move code (initial commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Feb 28, 2024
0 parents commit ced0be7
Show file tree
Hide file tree
Showing 225 changed files with 26,732 additions and 0 deletions.
114 changes: 114 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
*.untracked
*.untracked.*


# Misc
.DS_Store
.eslintcache
.env.local
.env.development.local
.env.test.local
.env.production.local


npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log
ui-debug.log
.pnpm-debug.log
.husky
tmp

# Dependencies
node_modules

# Build dirs
.env.*
.next
build
dist

# Generated files
.docusaurus
.cache-loader
**.tsbuildinfo

.xata*

# Development app
apps/dev/src/css
apps/dev/prisma/migrations
apps/dev/typeorm
apps/dev/nextjs-2

# VS
/.vs/slnx.sqlite-journal
/.vs/slnx.sqlite
/.vs
.vscode/generated*

# Jetbrains
.idea

# GitHub Actions runner
/actions-runner
/_work

# DB
dev.db*
packages/adapter-prisma/prisma/dev.db
packages/adapter-prisma/prisma/migrations
db.sqlite
packages/adapter-supabase/supabase/.branches
packages/adapter-drizzle/.drizzle

# Tests
coverage
dynamodblocal-bin
firestore-debug.log
test.schema.gql
test-results
playwright-report
blob-report
playwright/.cache


# Turborepo
.turbo

# docusaurus
docs/.docusaurus
docs/manifest.mjs

# Core
packages/core/src/providers/oauth-types.ts
packages/core/lib
packages/core/providers
docs/docs/reference/core

# Next.js
docs/docs/reference/nextjs

# SvelteKit
packages/frameworks-sveltekit/index.*
packages/frameworks-sveltekit/client.*
packages/frameworks-sveltekit/.svelte-kit
packages/frameworks-sveltekit/package
packages/frameworks-sveltekit/vite.config.js.timestamp-*
packages/frameworks-sveltekit/vite.config.ts.timestamp-*
docs/docs/reference/sveltekit

# SolidStart
docs/docs/reference/solidstart


# Express
docs/docs/reference/express


# Adapters
docs/docs/reference/adapter

## Drizzle migration folder
.drizzle
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.tabSize": 2,
}
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# stack

## Getting Started

Make sure you have `pnpm` installed alongside Node v20. Next, ensure you created `.env.local` files by copying `.env` in each of the subpackages in the `packages` folder and filling out the variables. You will need to start a Postgres database; you can do this with the following command:

```sh
docker run -it --rm -e POSTGRES_PASSWORD=password -p "5432:5432" postgres
```

Then:

```sh
pnpm install

# Run code generation (repeat this after eg. changing the Prisma schema)
pnpm run codegen

# After starting a Postgres database and filling the corresponding variables in .env.local, push the schema to the database:
pnpm run prisma:server -- db reset

# Start the dev server
pnpm run dev
```

To do linting and typechecking:

```sh
pnpm run codegen
```

You can also open Prisma Studio to see the database interface and edit data directly:

```sh
pnpm run prisma:server -- studio
```

# stack
4 changes: 4 additions & 0 deletions apps/nextjs/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXT_PUBLIC_STACK_URL=# enter your stack endpoint here, e.g. http://localhost:8101
NEXT_PUBLIC_STACK_PROJECT_ID=# enter your stack project id here
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=# enter your stack publishable client key here
STACK_SECRET_SERVER_KEY=# enter your stack secret server key here
22 changes: 22 additions & 0 deletions apps/nextjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
"extends": [
"../../eslint-configs/defaults.js",
"../../eslint-configs/next.js",
],
"ignorePatterns": ['/*', '!/src'],
rules: {
"import/order": [
1,
{
groups: [
"external",
"builtin",
"internal",
"sibling",
"parent",
"index",
],
},
],
},
};
7 changes: 7 additions & 0 deletions apps/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
dbschema/edgeql-js

*.tsbuildinfo
4 changes: 4 additions & 0 deletions apps/nextjs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"typescript.tsdk": "../../../node_modules/.pnpm/[email protected]/node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
5 changes: 5 additions & 0 deletions apps/nextjs/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
7 changes: 7 additions & 0 deletions apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("next").NextConfig} */
module.exports = {
webpack(config) {
config.experiments = { ...config.experiments, topLevelAwait: true }
return config
},
}
26 changes: 26 additions & 0 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "dev-app",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"typecheck": "tsc --noEmit",
"clean": "rm -rf .next",
"dev": "next dev --port 8102",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "14.0.4",
"next-themes": "^0.2.1",
"react": "^18",
"react-dom": "^18",
"stack": "workspace:*",
"stack-shared": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.8"
}
}
6 changes: 6 additions & 0 deletions apps/nextjs/src/app/handler/[...stack]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { StackHandler } from "stack";
import { stackServerApp } from "src/stack";

export default function Handler(props) {
return <StackHandler app={stackServerApp} {...props} />;
}
25 changes: 25 additions & 0 deletions apps/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StackProvider } from "stack";
import { stackServerApp } from "src/stack";
import Provider from "src/components/Provider";


export default function RootLayout({
children,
}: {
children: React.ReactNode,
}) {
return (
<html lang="en" suppressHydrationWarning>
<head />
<body>
<StackProvider
app={stackServerApp}
>
<Provider>
{children}
</Provider>
</StackProvider>
</body>
</html>
);
}
43 changes: 43 additions & 0 deletions apps/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Link from 'next/link';
import { stackServerApp } from 'src/stack';
import ColorModeButton from 'src/components/ColorThemeButton';
import SignOutButton from 'src/components/SignOutButton';
import UserInfo from 'src/components/UserInfo';
import UserInfoClient from 'src/components/UserInfoClient';

export default async function Page() {
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<div>
<div>Server:</div>
<UserInfo />
<div style={{ marginBottom: '1rem' }}/>
<div>Client:</div>
<UserInfoClient />
</div>

<div style={{ marginBottom: '1rem' }}/>
<Link href="/handler/signin">
Sign in
</Link>
<Link href="/handler/signup">
Sign up
</Link>
<div style={{ marginBottom: '1rem' }}/>
<SignOutButton />
<Link href={stackServerApp.urls['signOut']}>
Sign out (server)
</Link>
<div style={{ marginBottom: '1rem' }}/>
<ColorModeButton />

<div style={{ marginBottom: '1rem' }}/>
<Link href="/protected-client">
Protected client
</Link>
<Link href="/protected-server">
Protected server
</Link>
</div>
);
}
7 changes: 7 additions & 0 deletions apps/nextjs/src/app/protected-client/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';
import { useUser } from "stack";

export default function ProtectedPage() {
useUser({ or: 'redirect' });
return <div>This is protected. You can see this because you are signed in</div>;
}
6 changes: 6 additions & 0 deletions apps/nextjs/src/app/protected-server/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { stackServerApp } from "src/stack";

export default async function ProtectedPage() {
await stackServerApp.getUser({ or: 'redirect' });
return <div>This is protected. You can see this because you are signed in</div>;
}
36 changes: 36 additions & 0 deletions apps/nextjs/src/app/signin/custom-credential.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
'use client';
import { useStackApp, validateEmail } from "stack";
import { useState } from "react";

export default function CustomCredentialSignIn() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const app = useStackApp();

const onSubmit = async () => {
if (!validateEmail(email)) {
setError('Please enter a valid email');
return;
}
if (!password) {
setError('Please enter your password');
return;
}
const errorCode = await app.signInWithCredential({ email, password, redirectUrl: app.urls.userHome });
// It is better to handle each error code separately, but for simplicity, we will just show the error code directly
if (errorCode) {
setError(errorCode);
}
};

return (
<div>
{error}
<input type='email' placeholder="[email protected]" value={email} onChange={(e) => setEmail(e.target.value)} />
<input type='password' placeholder="password" value={password} onChange={(e) => setPassword(e.target.value)} />
<button onClick={onSubmit}>Sign In</button>
</div>
);
}
12 changes: 12 additions & 0 deletions apps/nextjs/src/app/signin/custom-oauth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
'use client';
import { useStackApp } from "stack";

export default function CustomOAuthSignIn() {
const app = useStackApp();

return <div>
<h1>My Custom Sign In page</h1>
<button onClick={async () => await app.signInWithOauth('google')}>Sign In with Google</button>
</div>;
}
Loading

0 comments on commit ced0be7

Please sign in to comment.