Skip to content

Commit 2bcd3fa

Browse files
committed
formatted code according to project + minor update
1 parent 817e43d commit 2bcd3fa

File tree

23 files changed

+263
-284
lines changed

23 files changed

+263
-284
lines changed

examples/with-solidstart/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ To ensure Web3-related logic runs only on the client, use the `clientOnly` utili
4040
1. **Client-Only Component** (e.g. for a component showing user balance)
4141

4242
```jsx
43-
import { clientOnly } from "@solidjs/start/client";
43+
import { clientOnly } from '@solidjs/start/client'
4444

45-
const ClientComponent = clientOnly(() => import("./ClientOnlyComponent"));
45+
const ClientComponent = clientOnly(() => import('./ClientOnlyComponent'))
4646
```
4747

4848
2. **Client-Only Page** (e.g. for a `/swap` page)
4949
Add the following at the top of your route file to render the entire page on the client:
5050

5151
```jsx
52-
import { clientOnly } from "@solidjs/start/client";
52+
import { clientOnly } from '@solidjs/start/client'
5353

54-
export default clientOnly(async () => ({ default: MyPage }));
54+
export default clientOnly(async () => ({ default: MyPage }))
5555
```
5656

5757
For more details, refer to the `clientOnly` [documentation](https://docs.solidjs.com/solid-start/reference/client/client-only#clientonly).
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { defineConfig } from "@solidjs/start/config";
2-
import tailwindcss from "@tailwindcss/vite";
1+
import { defineConfig } from '@solidjs/start/config'
2+
import tailwindcss from '@tailwindcss/vite'
33

44
export default defineConfig({
5-
server: { preset: "" }, // your deployment
5+
server: { preset: '' }, // your deployment
66
vite: { plugins: [tailwindcss()] }
7-
});
7+
})

examples/with-solidstart/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"scripts": {
44
"dev": "vinxi dev --port 3001",
55
"build": "vinxi build",
6-
"start": "vinxi start",
7-
"format": "prettier --write . --trailing-comma none"
6+
"start": "vinxi start"
87
},
98
"dependencies": {
109
"@solidjs/meta": "^0.29.4",
@@ -19,7 +18,6 @@
1918
},
2019
"devDependencies": {
2120
"@tailwindcss/vite": "^4.1.16",
22-
"prettier": "^3.6.2",
2321
"tailwindcss": "^4.1.16"
2422
},
2523
"engines": {

examples/with-solidstart/src/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "tailwindcss";
1+
@import 'tailwindcss';
22

33
#app {
44
background-color: white;
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Suspense } from "solid-js";
2-
import { Router, type RouteDefinition } from "@solidjs/router";
3-
import { FileRoutes } from "@solidjs/start/router";
4-
import { MetaProvider } from "@solidjs/meta";
5-
import { querySession } from "./auth";
6-
import AuthProvider from "./auth/Provider";
7-
import Nav from "./components/Nav";
8-
import ErrorNotification from "./components/Error";
9-
import "./app.css";
1+
import { Suspense } from 'solid-js'
2+
import { Router, type RouteDefinition } from '@solidjs/router'
3+
import { FileRoutes } from '@solidjs/start/router'
4+
import { MetaProvider } from '@solidjs/meta'
5+
import { querySession } from './auth'
6+
import AuthProvider from './auth/Provider'
7+
import Nav from './components/Nav'
8+
import ErrorNotification from './components/Error'
9+
import './app.css'
1010

1111
export const route: RouteDefinition = {
1212
preload: ({ location }) => querySession(location.pathname)
13-
};
13+
}
1414

1515
export default function App() {
1616
return (
1717
<Router
18-
root={(props) => (
18+
root={props => (
1919
<MetaProvider>
2020
<AuthProvider>
2121
<Suspense>
@@ -29,5 +29,5 @@ export default function App() {
2929
>
3030
<FileRoutes />
3131
</Router>
32-
);
32+
)
3333
}
Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,97 @@
1-
import { createEffect, createResource, on, type ParentProps } from "solid-js";
1+
import { createEffect, createResource, on, type ParentProps } from 'solid-js'
22
import {
33
useLocation,
44
createAsync,
55
useAction,
66
useSearchParams
7-
} from "@solidjs/router";
8-
import injectedWallets from "@web3-onboard/injected-wallets";
9-
import { signOutAction, querySession } from "~/auth";
10-
import { sign, authWalletAction, addWalletAction } from "~/auth/web3";
11-
import useWeb3Onboard, { BASE_ID, load } from "~/web3";
12-
import Context from "./context";
7+
} from '@solidjs/router'
8+
import injectedWallets from '@web3-onboard/injected-wallets'
9+
import { signOutAction, querySession } from '~/auth'
10+
import { sign, authWalletAction, addWalletAction } from '~/auth/web3'
11+
import useWeb3Onboard, { BASE_ID, load } from '~/web3'
12+
import Context from './context'
1313

1414
export default function AuthProvider(props: ParentProps) {
15-
const location = useLocation();
16-
const [searchParams, setSearchParams] = useSearchParams();
15+
const location = useLocation()
16+
const [searchParams, setSearchParams] = useSearchParams()
1717
const session = createAsync(() => querySession(location.pathname), {
1818
deferStream: true
19-
});
19+
})
2020

21-
const authWallet = useAction(authWalletAction);
22-
const addWallet = useAction(addWalletAction);
23-
const signOut = useAction(signOutAction);
24-
const signedIn = () => Boolean(session()?.id);
21+
const authWallet = useAction(authWalletAction)
22+
const addWallet = useAction(addWalletAction)
23+
const signOut = useAction(signOutAction)
24+
const signedIn = () => Boolean(session()?.id)
2525

2626
const onboard = useWeb3Onboard({
2727
wallets: [injectedWallets()],
2828
connect: { autoConnectLastWallet: true },
2929
chains: [{ id: BASE_ID }],
3030
appMetadata: {
31-
name: "SolidStart",
32-
description: "SolidStart web3-onboard template",
33-
icon: "favicon.svg"
31+
name: 'SolidStart',
32+
description: 'SolidStart web3-onboard template',
33+
icon: 'favicon.svg'
3434
}
35-
});
35+
})
3636

3737
createResource(
38-
() => searchParams.login === "true" && !signedIn() && onboard,
39-
async (instance) => {
38+
() => searchParams.login === 'true' && !signedIn() && onboard,
39+
async instance => {
4040
try {
41-
const [wallet] = await instance.connectWallet();
42-
if (!wallet?.provider) throw new Error("Wallet connection failed");
43-
const address = await sign(wallet.provider);
44-
const r = searchParams.redirect;
45-
await authWallet(address, Array.isArray(r) ? r[0] : r);
41+
const [wallet] = await instance.connectWallet()
42+
if (!wallet?.provider) throw new Error('Wallet connection failed')
43+
const address = await sign(wallet.provider)
44+
const r = searchParams.redirect
45+
await authWallet(address, Array.isArray(r) ? r[0] : r)
4646
} catch (err) {
4747
setSearchParams({
48-
error: err instanceof Error ? err.message : "",
49-
login: ""
50-
});
48+
error: err instanceof Error ? err.message : '',
49+
login: ''
50+
})
5151
}
5252
}
53-
);
53+
)
5454

5555
const [web3] = createResource(
5656
onboard?.connectedWallet,
5757
async ({ provider }) => {
5858
if (onboard!.connectedChain().id !== BASE_ID)
59-
await onboard!.setChain({ chainId: BASE_ID });
60-
return load(provider);
59+
await onboard!.setChain({ chainId: BASE_ID })
60+
return load(provider)
6161
}
62-
);
62+
)
6363

6464
createEffect(
6565
on(
6666
() => onboard?.walletAddress(),
6767
async (current, previous) => {
68-
const saved = session()?.wallets;
69-
if (!saved?.length || !previous) return;
70-
if (!current) await signOut();
68+
const saved = session()?.wallets
69+
if (!saved?.length || !previous) return
70+
if (!current) await signOut()
7171
if (current && current !== previous) {
7272
try {
73-
const { provider } = onboard!.connectedWallet();
74-
const addr = current.toLowerCase();
75-
const verified = saved.includes(addr) ? addr : await sign(provider);
76-
await addWallet(verified);
73+
const { provider } = onboard!.connectedWallet()
74+
const addr = current.toLowerCase()
75+
const verified = saved.includes(addr) ? addr : await sign(provider)
76+
await addWallet(verified)
7777
} catch (err) {
78-
setSearchParams({ error: err instanceof Error ? err.message : "" });
78+
setSearchParams({ error: err instanceof Error ? err.message : '' })
7979
}
8080
}
8181
},
8282
{ defer: true }
8383
)
84-
);
84+
)
8585

8686
const logout = async () => {
87-
try {
88-
const wallet = onboard?.connectedWallet();
89-
if (wallet) {
90-
await onboard!.disconnectWallet({ label: wallet.label });
91-
}
92-
} finally {
93-
await signOut();
94-
}
95-
};
96-
};
97-
98-
return (
87+
const wallet = onboard?.connectedWallet()
88+
if (wallet) await onboard!.disconnectWallet({ label: wallet.label })
89+
return signOut()
90+
}
9991

10092
return (
10193
<Context.Provider value={{ session, signedIn, logout, web3 }}>
10294
{props.children}
10395
</Context.Provider>
104-
);
96+
)
10597
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { createContext, type Resource } from "solid-js";
2-
import type { AccessorWithLatest } from "@solidjs/router";
3-
import type { Session } from "~/auth/server";
4-
import type { Web3 } from "~/web3";
1+
import { createContext, type Resource } from 'solid-js'
2+
import type { AccessorWithLatest } from '@solidjs/router'
3+
import type { Session } from '~/auth/server'
4+
import type { Web3 } from '~/web3'
55

66
interface Context {
7-
session: AccessorWithLatest<Session | undefined>;
8-
signedIn: () => boolean;
9-
logout: () => Promise<never>;
10-
web3: Resource<Web3>;
7+
session: AccessorWithLatest<Session | undefined>
8+
signedIn: () => boolean
9+
logout: () => Promise<never>
10+
web3: Resource<Web3>
1111
}
1212

13-
export default createContext<Context>();
13+
export default createContext<Context>()
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import { useContext } from "solid-js";
2-
import { query, redirect, action } from "@solidjs/router";
3-
import { getSession } from "./server";
4-
import context from "./context";
1+
import { useContext } from 'solid-js'
2+
import { query, redirect, action } from '@solidjs/router'
3+
import { getSession } from './server'
4+
import context from './context'
55

6-
const PROTECTED_ROUTES = ["/"];
6+
const PROTECTED_ROUTES = ['/']
77

88
export const protectedRoute = (path: string) =>
9-
PROTECTED_ROUTES.some((route) =>
10-
route.endsWith("/*")
9+
PROTECTED_ROUTES.some(route =>
10+
route.endsWith('/*')
1111
? path.startsWith(route.slice(0, -2))
12-
: path === route || path.startsWith(route + "/")
13-
);
12+
: path === route || path.startsWith(route + '/')
13+
)
1414

1515
export const querySession = query(async (path: string) => {
16-
"use server";
17-
const { data: session } = await getSession();
18-
if (session.wallets?.length) return session;
19-
if (protectedRoute(path))
20-
throw redirect("/about?login=true&redirect=" + path);
21-
}, "querySession");
16+
'use server'
17+
const { data: session } = await getSession()
18+
if (session.wallets?.length) return session
19+
if (protectedRoute(path)) throw redirect('/about?login=true&redirect=' + path)
20+
}, 'querySession')
2221

2322
export const signOutAction = action(async () => {
24-
"use server";
25-
const session = await getSession();
26-
await session.update({ wallets: undefined });
27-
throw redirect("/about", { revalidate: querySession.key });
28-
});
23+
'use server'
24+
const session = await getSession()
25+
await session.update({ wallets: undefined })
26+
throw redirect('/about', { revalidate: querySession.key })
27+
})
2928

3029
export default function useAuth() {
31-
const ctx = useContext(context);
32-
if (!ctx) throw new Error("useAuth must be used within AuthProvider");
33-
return ctx;
30+
const ctx = useContext(context)
31+
if (!ctx) throw new Error('useAuth must be used within AuthProvider')
32+
return ctx
3433
}
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
import { redirect } from "@solidjs/router";
2-
import { useSession } from "vinxi/http";
1+
import { redirect } from '@solidjs/router'
2+
import { useSession } from 'vinxi/http'
33

44
export interface Session {
5-
id: number | undefined;
6-
wallets: string[] | undefined;
5+
id: number | undefined
6+
wallets: string[] | undefined
77
}
88

99
export const getSession = () =>
10-
useSession<Session>({
11-
name: "session",
12-
password: process.env.SESSION_SECRET!,
13-
cookie: {
14-
secure: true,
15-
sameSite: "lax",
16-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
17-
httpOnly: true
18-
}
19-
});
10+
useSession<Session>({ password: process.env.SESSION_SECRET! })
2011

2112
export const updateSession = async (wallets: string[], id?: number) => {
22-
const session = await getSession();
13+
const session = await getSession()
2314
const { data } = await session.update(() => ({
2415
id: id || session.data.id,
2516
wallets
26-
}));
27-
return data as Session;
28-
};
17+
}))
18+
return data as Session
19+
}
2920

3021
export const safeRedirect = (url?: string) =>
31-
redirect(url?.startsWith("/") && !url.startsWith("//") ? url : "/");
22+
redirect(url?.startsWith('/') && !url.startsWith('//') ? url : '/')

0 commit comments

Comments
 (0)