Skip to content

Commit

Permalink
feat: use latest's auth api
Browse files Browse the repository at this point in the history
  • Loading branch information
OrJDev committed Oct 8, 2024
1 parent 0681403 commit a6e45df
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 89 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-foxes-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-jd-app": patch
---

feat: use latest's auth api
2 changes: 1 addition & 1 deletion src/helpers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const packages = {
"@solid-mediakit/prpc": "^1.3.3",
"@solid-mediakit/prpc-plugin": "^1.3.4",
// authjs
"@solid-mediakit/auth": "^2.1.6",
"@solid-mediakit/auth": "^3.0.0",
"@solid-mediakit/auth-plugin": "^1.1.4",
"@auth/core": "0.35.0",
"@auth/prisma-adapter": "^2.6.0",
Expand Down
44 changes: 22 additions & 22 deletions template/index/with-auth-prpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type VoidComponent, Suspense, Show } from "solid-js";
import { A } from "@solidjs/router";
import { createSession, signOut, signIn } from "@solid-mediakit/auth/client";
import { useAuth } from "@solid-mediakit/auth/client";
import { type VoidComponent, Match, Switch } from "solid-js";
import { helloQuery } from "~/server/hello/hello.queries";

const Home: VoidComponent = () => {
Expand Down Expand Up @@ -38,9 +38,7 @@ const Home: VoidComponent = () => {
<p class="text-2xl text-white">
{hello.data ?? "Loading pRPC query"}
</p>
<Suspense>
<AuthShowcase />
</Suspense>
<AuthShowcase />
</div>
</div>
</main>
Expand All @@ -50,30 +48,32 @@ const Home: VoidComponent = () => {
export default Home;

const AuthShowcase: VoidComponent = () => {
const session = createSession();
const auth = useAuth();
return (
<div class="flex flex-col items-center justify-center gap-4">
<Show
when={session().status === "authenticated"}
fallback={
<Switch fallback={<div>Loading...</div>}>
<Match when={auth.status() === "authenticated"}>
<div class="flex flex-col gap-3">
<span class="text-xl text-white">
Welcome {auth.session()?.user?.name}
</span>
<button
onClick={() => auth.signOut({ redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign out
</button>
</div>
</Match>
<Match when={auth.status() === "unauthenticated"}>
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
onClick={() => auth.signIn("discord", { redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign in
</button>
}
>
<span class="text-xl text-white">
Welcome {session().data?.user?.name}
</span>
<button
onClick={() => signOut({ redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign out
</button>
</Show>
</Match>
</Switch>
</div>
);
};
42 changes: 20 additions & 22 deletions template/index/with-auth-prpc.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styles from "./index.module.css";
import { type VoidComponent, Suspense, Show } from "solid-js";
import { A } from "@solidjs/router";
import { createSession, signOut, signIn } from "@solid-mediakit/auth/client";
import { useAuth } from "@solid-mediakit/auth/client";
import { type VoidComponent, Match, Switch } from "solid-js";
import { helloQuery } from "~/server/hello/hello.queries";

const Home: VoidComponent = () => {
Expand Down Expand Up @@ -39,9 +39,7 @@ const Home: VoidComponent = () => {
<p class={styles.showcaseText}>
{hello.data ?? "Loading pRPC query"}
</p>
<Suspense>
<AuthShowcase />
</Suspense>
<AuthShowcase />
</div>
</div>
</main>
Expand All @@ -51,30 +49,30 @@ const Home: VoidComponent = () => {
export default Home;

const AuthShowcase: VoidComponent = () => {
const session = createSession();
const auth = useAuth();
return (
<div class={styles.authContainer}>
<Show
when={session().status === "authenticated"}
fallback={
<Switch fallback={<div>Loading...</div>}>
<Match when={auth.status() === "authenticated"}>
<span class={styles.showcaseText}>
Welcome {auth.session()?.user?.name}
</span>
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
onClick={() => auth.signOut({ redirectTo: "/" })}
class={styles.loginButton}
>
Sign out
</button>
</Match>
<Match when={auth.status() === "unauthenticated"}>
<button
onClick={() => auth.signIn("discord", { redirectTo: "/" })}
class={styles.loginButton}
>
Sign in
</button>
}
>
<span class={styles.showcaseText}>
Welcome {session()?.data?.user?.name}
</span>
<button
onClick={() => signOut({ redirectTo: "/" })}
class={styles.loginButton}
>
Sign out
</button>
</Show>
</Match>
</Switch>
</div>
);
};
44 changes: 22 additions & 22 deletions template/index/with-auth-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type VoidComponent, Suspense, Show } from "solid-js";
import { A } from "@solidjs/router";
import { createSession, signOut, signIn } from "@solid-mediakit/auth/client";
import { useAuth } from "@solid-mediakit/auth/client";
import { type VoidComponent, Match, Switch } from "solid-js";

const Home: VoidComponent = () => {
return (
Expand Down Expand Up @@ -32,9 +32,7 @@ const Home: VoidComponent = () => {
</div>
</A>
</div>
<Suspense>
<AuthShowcase />
</Suspense>
<AuthShowcase />
</div>
</main>
);
Expand All @@ -43,30 +41,32 @@ const Home: VoidComponent = () => {
export default Home;

const AuthShowcase: VoidComponent = () => {
const session = createSession();
const auth = useAuth();
return (
<div class="flex flex-col items-center justify-center gap-4">
<Show
when={session().status === "authenticated"}
fallback={
<Switch fallback={<div>Loading...</div>}>
<Match when={auth.status() === "authenticated"}>
<div class="flex flex-col gap-3">
<span class="text-xl text-white">
Welcome {auth.session()?.user?.name}
</span>
<button
onClick={() => auth.signOut({ redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign out
</button>
</div>
</Match>
<Match when={auth.status() === "unauthenticated"}>
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
onClick={() => auth.signIn("discord", { redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign in
</button>
}
>
<span class="text-xl text-white">
Welcome {session().data?.user?.name}
</span>
<button
onClick={() => signOut({ redirectTo: "/" })}
class="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
>
Sign out
</button>
</Show>
</Match>
</Switch>
</div>
);
};
42 changes: 20 additions & 22 deletions template/index/with-auth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styles from "./index.module.css";
import { type VoidComponent, Suspense, Show } from "solid-js";
import { A } from "@solidjs/router";
import { createSession, signOut, signIn } from "@solid-mediakit/auth/client";
import { useAuth } from "@solid-mediakit/auth/client";
import { type VoidComponent, Match, Switch } from "solid-js";

const Home: VoidComponent = () => {
return (
Expand Down Expand Up @@ -33,9 +33,7 @@ const Home: VoidComponent = () => {
</div>
</A>
</div>
<Suspense>
<AuthShowcase />
</Suspense>
<AuthShowcase />
</div>
</main>
);
Expand All @@ -44,30 +42,30 @@ const Home: VoidComponent = () => {
export default Home;

const AuthShowcase: VoidComponent = () => {
const session = createSession();
const auth = useAuth();
return (
<div class={styles.authContainer}>
<Show
when={session().status === "authenticated"}
fallback={
<Switch fallback={<div>Loading...</div>}>
<Match when={auth.status() === "authenticated"}>
<span class={styles.showcaseText}>
Welcome {auth.session()?.user?.name}
</span>
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
onClick={() => auth.signOut({ redirectTo: "/" })}
class={styles.loginButton}
>
Sign out
</button>
</Match>
<Match when={auth.status() === "unauthenticated"}>
<button
onClick={() => auth.signIn("discord", { redirectTo: "/" })}
class={styles.loginButton}
>
Sign in
</button>
}
>
<span class={styles.showcaseText}>
Welcome {session()?.data?.user?.name}
</span>
<button
onClick={() => signOut({ redirectTo: "/" })}
class={styles.loginButton}
>
Sign out
</button>
</Show>
</Match>
</Switch>
</div>
);
};

0 comments on commit a6e45df

Please sign in to comment.