Skip to content

Commit

Permalink
moved auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampouse committed Dec 21, 2024
1 parent 35b25cf commit 5bf48ac
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"devDependencies": {
"@auth/core": "0.31.0",
"@auth/qwik": "0.2.2",
"@builder.io/qwik": "latest",
"@builder.io/qwik-auth": "0.2.2",
"@builder.io/qwik-city": "latest",
Expand Down
40 changes: 40 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/components/dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { component$ } from "@builder.io/qwik";
import { Form } from "@builder.io/qwik-city";
import { useAuthSignout } from "~/routes/plugin@auth";
import { Dropdown } from "@qwik-ui/headless";
import { Link } from "@builder.io/qwik-city";
import { useAuthSession } from "~/routes/plugin@auth";
import { useSession, useSignOut } from "~/routes/plugin@auth";
export default component$(() => {
type Session = ReturnType<typeof useAuthSession>;
const session = useAuthSession() as Session;
const signout = useAuthSignout();
type Session = ReturnType<typeof useSession>;
const session = useSession() as Session;
const signout = useSignOut();
const img = session.value?.user?.image || "https://s6.imgcdn.dev/LyfCg.jpg";
const actions = [
{ label: "Profile", disabled: false, path: "/profile" },
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/Mainheader.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { component$, useTask$, useVisibleTask$ } from "@builder.io/qwik";
import { useAuthSession } from "~/routes/plugin@auth";
import { useSession } from "~/routes/plugin@auth";
import { useLocation } from "@builder.io/qwik-city";
import { useSignal } from "@builder.io/qwik";
import { Link } from "@builder.io/qwik-city";
import { ArrowLeftIcon } from "lucide-qwik";
import Dropdown from "@/components/dropdown";
import posthog from "posthog-js";
export default component$(() => {
const session = useAuthSession();
const session = useSession();
//eslint-disable-next-line
useVisibleTask$(() => {
if (document.location.host.includes("study-hack.vercel.app")) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Modal } from "@qwik-ui/headless";
import { component$, type Signal } from "@builder.io/qwik";
import { useAuthSession } from "~/routes/plugin@auth";
import { useSession } from "~/routes/plugin@auth";

type CardProps = {
data: { name: string; about: string; interests: string[] };
Expand All @@ -9,7 +9,7 @@ type CardProps = {
};

export default component$<CardProps>(({ data }) => {
const session = useAuthSession();
const session = useSession();
const image = session.value?.user?.image;
return (
<div class="flex flex-col items-center gap-5 py-8 md:flex-row md:gap-5 md:pt-12 lg:items-start ">
Expand Down
4 changes: 2 additions & 2 deletions src/routes/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthSignin } from "../plugin@auth";
import { useSignIn } from "../plugin@auth";
import { component$ } from "@builder.io/qwik";
import { GoogleIcon, GithubIcon } from "~/components/icons";
import { Form } from "@builder.io/qwik-city";
Expand All @@ -25,7 +25,7 @@ export const onGet: RequestHandler = async (req) => {
};

export default component$(() => {
const signin = useAuthSignin();
const signin = useSignIn();
return (
<div class="flex h-fit flex-col items-center justify-around bg-white py-10 shadow-sm lg:pt-4">
<JustRnd class="h-72 w-72" />
Expand Down
20 changes: 9 additions & 11 deletions src/routes/[email protected]
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { serverAuth$ } from "@builder.io/qwik-auth";
import GitHub from "@auth/core/providers/github";
import type { Provider } from "@auth/core/providers";
import { QwikAuth$ } from "@auth/qwik";
import GitHub from "@auth/qwik/providers/github";

export const { onRequest, useAuthSession, useAuthSignin, useAuthSignout } =
serverAuth$(({ env }) => ({
secret: env.get("AUTH_SECRET"),
trustHost: true,
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
(params) => ({
providers: [
GitHub({
clientId: env.get("GITHUB_ID")!,
clientSecret: env.get("GITHUB_SECRET")!,
clientId: params.env.get("GITHUB_ID"),
clientSecret: params.env.get("GITHUB_SECRET"),
}),
] as Provider[],
}));
],
}),
);

0 comments on commit 5bf48ac

Please sign in to comment.