Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click event not working in protected route. #1812

Closed
ankurpowar opened this issue Feb 15, 2025 · 3 comments
Closed

Click event not working in protected route. #1812

ankurpowar opened this issue Feb 15, 2025 · 3 comments

Comments

@ankurpowar
Copy link

So I have added the "authentication" as shown in the docs And it is working fine.
But the click events not working on the button.

Auth.js

import { clearSession, getSession, useSession } from "vinxi/http";

export async function createSession() {
  "use server";
  return await useSession({
    password: "SomeTokenButIDontKnowForWhatSomeTokenButIDontKnowForWhatSomeTokenButIDontKnowForWhat",
    cookie: {
      secure: false,
      httpOnly: true,
    },
  });
}

export async function readSession() {
  "use server";
  return await getSession({
    password: "SomeTokenButIDontKnowForWhatSomeTokenButIDontKnowForWhatSomeTokenButIDontKnowForWhat",

  });
}

export async function deleteSession() {
  "use server";
  return await clearSession();
}

User.jsx

import { createAsync, query, redirect } from "@solidjs/router";
import { readSession } from "~/backend/auth";

const getUser = query(async () => {
  "use server";

  const session = await readSession()
  
  if (!session?.data?.email) {
    throw redirect("/log-in");
  }

  return { email: session.data.email }

})

export default function User(props) {
  const user = createAsync(() => getUser(), { deferStream: true });
  const handleClick = ()=>{
    console.log('button clicked')
  }

  return (
    <div>
      <div class="sf-my-container">
        <h1>Hello,</h1>
        <h2>{user()?.email}</h2>
        <button onClick={handleClick}>Click me</button>
      </div>
      {props.children}
    </div>

  )
}

If i only keep the following version of User.jsx it still doesn't work.

import { createAsync, query, redirect } from "@solidjs/router";
import { readSession } from "~/backend/auth";

export default function User(props) {
  const handleClick = ()=>{
    console.log('button clicked')
  }

  return (
    <div>
      <div class="sf-my-container">
        <h1>Hello,</h1>
        <button onClick={handleClick}>Click me</button>
      </div>
      {props.children}
    </div>

  )
}

But as soon as i remove "readSession" import , the click event starts working.

@ankurpowar
Copy link
Author

So I was using solidstart 1.0.10 and now I upgraded it latest version and the problem seems to be resolved.

@brenelz
Copy link
Contributor

brenelz commented Feb 15, 2025

@ankurpowar Is it alright if I close this issue then?

@ankurpowar
Copy link
Author

Yes, Please.

@brenelz brenelz closed this as completed Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants