Skip to content

Commit 1816b84

Browse files
committed
updated with-auth example
1 parent c06be58 commit 1816b84

5 files changed

Lines changed: 42 additions & 22 deletions

File tree

examples/pnpm-lock.yaml

Lines changed: 34 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@solidjs/router": "^0.15.3",
1111
"@solidjs/start": "^1.1.7",
1212
"solid-js": "^1.9.7",
13-
"start-oauth": "^1.2.0",
13+
"start-oauth": "^1.2.2",
1414
"unstorage": "1.16.1",
1515
"vinxi": "^0.5.8"
1616
},

examples/with-auth/src/components/Counter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function Counter() {
66
return (
77
<button
88
class="w-[200px] rounded-full bg-gray-100 border-2 border-gray-300 focus:border-gray-400 active:border-gray-400 px-[2rem] py-[1rem]"
9-
onclick={() => setCount(count() + 1)}
9+
onclick={() => setCount(prev => prev + 1)}
1010
>
1111
Clicks: {count()}
1212
</button>

examples/with-auth/src/lib/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export const getSession = () =>
1212
password: process.env.SESSION_SECRET!
1313
});
1414

15-
export const createSession = async (user: Session, dest?: string) => {
16-
const validDest = dest?.[0] === "/" && dest[1] !== "/";
15+
export const createSession = async (user: Session, redirectTo?: string) => {
16+
const validDest = redirectTo?.[0] === "/" && redirectTo[1] !== "/";
1717
const session = await getSession();
1818
await session.update(user);
19-
return redirect(validDest ? dest : "/");
19+
return redirect(validDest ? redirectTo : "/");
2020
};
2121

22-
export const oauthSignIn = async (email: string, dest?: string) => {
22+
export const oauthSignIn = async (email: string, redirectTo?: string) => {
2323
let user = await findUser({ email });
2424
if (!user) user = await createUser({ email });
25-
return createSession(user, dest);
25+
return createSession(user, redirectTo);
2626
};
2727

2828
export const passwordSignIn = async (email: string, password: string) => {

examples/with-auth/src/routes/api/oauth/[...oauth].ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config: Configuration = {
77
id: process.env.DISCORD_ID!,
88
secret: process.env.DISCORD_SECRET!
99
},
10-
handler: async ({ email }, redirect) => oauthSignIn(email, redirect)
10+
handler: async ({ email }, redirectTo) => oauthSignIn(email, redirectTo)
1111
};
1212

1313
export const GET = OAuth(config);

0 commit comments

Comments
 (0)