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
30 changes: 30 additions & 0 deletions examples/with-supabase-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SolidStart

Everything you need to build a Solid project, powered by [`solid-start`](https://start.solidjs.com);

## Creating a project

```bash
# create a new project in the current directory
npm init solid@latest

# create a new project in my-app
npm init solid@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

Solid apps are built with _presets_, which optimise your project for deployment to different environments.

By default, `npm run build` will generate a Node app that you can run with `npm start`. To use a different preset, add it to the `devDependencies` in `package.json` and specify in your `app.config.js`.
3 changes: 3 additions & 0 deletions examples/with-supabase-auth/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({});
23 changes: 23 additions & 0 deletions examples/with-supabase-auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "example-with-tailwindcss",
"type": "module",
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
},
"dependencies": {
"@solidjs/router": "^0.15.3",
"@solidjs/start": "^1.1.1",
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.49.1",
"autoprefixer": "^10.4.20",
"postcss": "^8.5.3",
"solid-js": "^1.9.5",
"tailwindcss": "^3.4.3",
"vinxi": "^0.5.3"
},
"engines": {
"node": ">=18"
}
}
6 changes: 6 additions & 0 deletions examples/with-supabase-auth/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Binary file added examples/with-supabase-auth/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions examples/with-supabase-auth/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--background-rgb: 214, 219, 220;
--foreground-rgb: 0, 0, 0;
}

@media (prefers-color-scheme: dark) {
:root {
--background-rgb: 0, 0, 0;
--foreground-rgb: 255, 255, 255;
}
}

body {
background: rgb(var(--background-rgb));
color: rgb(var(--foreground-rgb));
}
21 changes: 21 additions & 0 deletions examples/with-supabase-auth/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
import { Navigation } from "~/components/navigation";
import "./app.css";
import { SupabaseSessionProvider } from "./util/supabase/session-context";

export default function App() {
return (
<Router
root={props => (
<SupabaseSessionProvider>
<Navigation />
<Suspense>{props.children}</Suspense>
</SupabaseSessionProvider>
)}
>
<FileRoutes />
</Router>
);
}
43 changes: 43 additions & 0 deletions examples/with-supabase-auth/src/components/navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { A, useAction, useLocation } from "@solidjs/router";
import { signOutAction } from "~/util/supabase/actions";
import { useSupabaseSession } from "~/util/supabase/session-context";

export function Navigation() {
const location = useLocation();
const session = useSupabaseSession();

const signOut = useAction(signOutAction);

const active = (path: string) =>
path == location.pathname ? "border-sky-600" : "border-transparent hover:border-sky-600";

return (
<nav class="bg-sky-800">
<ul class="container flex items-center p-3 text-gray-200">
<li class={`border-b-2 ${active("/")} mx-1.5 sm:mx-6`}>
<A href="/">Home</A>
</li>
<li class={`border-b-2 ${active("/about")} mx-1.5 sm:mx-6`}>
<A href="/about">About</A>
</li>
<li class={`border-b-2 ${active("/protected")} mx-1.5 sm:mx-6`}>
<A href="/protected">Protected</A>
</li>
{session() ? (
<li class={`border-b-2 ${active("nonsense-route")} mx-1.5 sm:mx-6`}>
<button onClick={() => signOut()}>Sign Out</button>
</li>
) : (
<>
<li class={`border-b-2 ${active("/sign-up")} mx-1.5 sm:mx-6`}>
<A href="/sign-up">Sign Up</A>
</li>
<li class={`border-b-2 ${active("/sign-in")} mx-1.5 sm:mx-6`}>
<A href="/sign-in">Sign In</A>
</li>
</>
)}
</ul>
</nav>
);
}
4 changes: 4 additions & 0 deletions examples/with-supabase-auth/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @refresh reload
import { mount, StartClient } from "@solidjs/start/client";

mount(() => <StartClient />, document.getElementById("app")!);
21 changes: 21 additions & 0 deletions examples/with-supabase-auth/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @refresh reload
import { createHandler, StartServer } from "@solidjs/start/server";

export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
{assets}
</head>
<body>
<div id="app">{children}</div>
{scripts}
</body>
</html>
)}
/>
));
1 change: 1 addition & 0 deletions examples/with-supabase-auth/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@solidjs/start/env" />
56 changes: 56 additions & 0 deletions examples/with-supabase-auth/src/routes/(auth)/forgot-password.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { A, useSubmission } from "@solidjs/router";
import { Show } from "solid-js";
import { forgotPasswordAction } from "~/util/supabase/actions";

export default function ForgotPassword() {
const forgetPassword = useSubmission(forgotPasswordAction);
return (
<main class="text-center mx-auto text-gray-700 dark:text-gray-500 p-4">
<h1 class="max-6-xs text-6xl text-sky-700 font-thin uppercase my-16">Reset Password</h1>
<form
action={forgotPasswordAction}
class="flex-1 flex flex-col w-full gap-2 text-foreground [&>input]:mb-6 min-w-64 max-w-64 mx-auto"
method="post"
>
<div>
<p class="text-sm text-foreground">
Already have an account?{" "}
<A class="text-primary underline" href="/sign-in">
Sign in
</A>
</p>
</div>
<div class="flex flex-col text-left gap-2 [&>input]:mb-3 mt-8">
<label for="email">Email</label>
<input
name="email"
class="text-black p-2 rounded"
placeholder="[email protected]"
required
/>
<button
class="p-2 border border-gray-300 hover:bg-white/10"
type="submit"
formAction={forgotPasswordAction}
>
Reset Password
</button>
<Show when={forgetPassword.result}>
{result => {
const submission = result();
return typeof submission === "string" ? (
<p class="w-full border p-2 mt-2 rounded-md border-green-600 text-green-600">
{submission}
</p>
) : (
<p class="w-full border p-2 mt-2 rounded-md border-red-600 text-red-600">
{submission.message}
</p>
);
}}
</Show>
</div>
</form>
</main>
);
}
59 changes: 59 additions & 0 deletions examples/with-supabase-auth/src/routes/(auth)/reset-password.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { type RouteDefinition, useSubmission } from "@solidjs/router";
import { Show } from "solid-js";
import { getProtectedUser, resetPasswordAction } from "~/util/supabase/actions";

export const route = {
preload() {
getProtectedUser();
}
} satisfies RouteDefinition;

export default function ResetPassword() {
const resetPassword = useSubmission(resetPasswordAction);
return (
<main class="text-center mx-auto text-gray-700 dark:text-gray-500 p-4">
<h1 class="max-6-xs text-6xl text-sky-700 font-thin uppercase my-16">Reset Password</h1>
<form
action={resetPasswordAction}
class="flex-1 flex flex-col w-full gap-2 text-foreground [&>input]:mb-6 min-w-64 max-w-64 mx-auto"
method="post"
>
<div>
<p class="text-sm text-foreground">Please enter your new password below.</p>
</div>
<div class="flex flex-col text-left gap-2 [&>input]:mb-3 mt-8">
<label for="password">New password</label>
<input
type="password"
name="password"
class="text-black p-2 rounded"
placeholder="New password"
required
/>
<label for="confirmPassword">Confirm password</label>
<input
type="password"
name="confirmPassword"
class="text-black p-2 rounded"
placeholder="Confirm password"
required
/>
<button
class="p-2 border border-gray-300 hover:bg-white/10"
formAction={resetPasswordAction}
type="submit"
>
Reset password
</button>
<Show when={resetPassword.result}>
{result => (
<p class="w-full border p-2 mt-2 rounded-md border-red-600 text-red-600">
{result().message}
</p>
)}
</Show>
</div>
</form>
</main>
);
}
53 changes: 53 additions & 0 deletions examples/with-supabase-auth/src/routes/(auth)/sign-in.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { A, useSubmission } from "@solidjs/router";
import { Show } from "solid-js";
import { signInAction } from "~/util/supabase/actions";

export default function Login() {
const signIn = useSubmission(signInAction);
return (
<main class="text-center mx-auto text-gray-700 dark:text-gray-500 p-4">
<h1 class="max-6-xs text-6xl text-sky-700 font-thin uppercase my-16">Sign In</h1>
<form action={signInAction} class="flex flex-col min-w-64 max-w-64 mx-auto" method="post">
<p class="text-sm text-foreground">
Don't have an account?{" "}
<A class="text-foreground font-medium underline" href="/sign-up">
Sign up
</A>
</p>
<div class="flex flex-col text-left gap-2 [&>input]:mb-3 mt-8">
<label for="email">Email</label>
<input
name="email"
type="email"
class="text-black p-2 rounded"
placeholder="[email protected]"
required
/>
<div class="flex justify-between items-center">
<label for="password">Password</label>
<A class="text-foreground underline" href="/forgot-password">
Forgot Password?
</A>
</div>
<input
type="password"
name="password"
class="text-black p-2 rounded"
placeholder="Your password"
required
/>
<button class="p-2 border border-gray-300 hover:bg-white/10" formAction={signInAction}>
Sign in
</button>
<Show when={signIn.result}>
{result => (
<p class="w-full border p-2 mt-2 rounded-md border-red-600 text-red-600">
{result().message}
</p>
)}
</Show>
</div>
</form>
</main>
);
}
Loading