-
Notifications
You must be signed in to change notification settings - Fork 0
Create a sign up page similar to sign in page #27
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
e759f72
f1907b5
2b867c6
012a1d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
VITE_CLERK_PUBLISHABLE_KEY=pk_test_123 | ||
|
||
VITE_CLERK_SIGN_IN_URL=/sign_in | ||
VITE_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/dashboard | ||
VITE_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/dashboard | ||
VITE_CLERK_PUBLISHABLE_KEY=pk_test_123 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class SessionsController < InertiaController | ||
skip_before_action :authenticate_user!, only: %i[ new ] | ||
skip_before_action :authenticate_user!, only: %i[ new create sign_up create_signup ] | ||
|
||
def new | ||
if user_signed_in? | ||
|
@@ -10,6 +10,39 @@ def new | |
end | ||
end | ||
|
||
def create | ||
# Handle Clerk token and create Rails session | ||
clerk_token = params[:clerk_token] | ||
|
||
if clerk_token.present? | ||
# The token verification is handled by the Clerk middleware | ||
# If we reach here, the user is authenticated | ||
head :ok | ||
else | ||
head :unauthorized | ||
end | ||
end | ||
|
||
def sign_up | ||
if user_signed_in? | ||
flash[:notice] = "You are already signed in" | ||
redirect_to root_path | ||
end | ||
end | ||
|
||
def create_signup | ||
|
||
# Handle Clerk token and create Rails session for sign-up | ||
clerk_token = params[:clerk_token] | ||
|
||
if clerk_token.present? | ||
# The token verification is handled by the Clerk middleware | ||
# If we reach here, the user is authenticated | ||
head :ok | ||
else | ||
head :unauthorized | ||
end | ||
end | ||
|
||
def switch | ||
# renders the account selector page | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { SignUp, useAuth } from "@clerk/clerk-react" | ||
import { Head, router } from "@inertiajs/react" | ||
import { useEffect } from "react" | ||
|
||
import AuthLayout from "@/layouts/auth-layout" | ||
|
||
export default function SignUpPage() { | ||
const { getToken, isSignedIn } = useAuth() | ||
|
||
useEffect(() => { | ||
const createSession = async () => { | ||
if (isSignedIn) { | ||
try { | ||
const token = await getToken() | ||
if (token) { | ||
// Post the clerk token to our backend to create a session | ||
await fetch("/sign_up", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-CSRF-Token": | ||
document | ||
.querySelector('meta[name="csrf-token"]') | ||
?.getAttribute("content") ?? "", | ||
}, | ||
body: JSON.stringify({ clerk_token: token }), | ||
}) | ||
|
||
// Redirect after successful session creation | ||
router.visit("/dashboard") | ||
} | ||
} catch (error) { | ||
console.error("Failed to create session:", error) | ||
} | ||
} | ||
} | ||
|
||
void createSession() | ||
}, [isSignedIn, getToken]) | ||
|
||
return ( | ||
<AuthLayout | ||
title="Welcome" | ||
description="Create your account to get started" | ||
> | ||
<Head title="Sign up" /> | ||
|
||
<div className="flex justify-center"> | ||
<SignUp routing="path" path="/sign_up" fallbackRedirectUrl="/switch" /> | ||
</div> | ||
|
||
<div className="text-muted-foreground mt-6 text-center text-xs"> | ||
By clicking continue, you agree to our{" "} | ||
<a href="#" className="hover:text-primary underline underline-offset-4"> | ||
Terms of Service | ||
</a>{" "} | ||
and{" "} | ||
<a href="#" className="hover:text-primary underline underline-offset-4"> | ||
Privacy Policy | ||
</a> | ||
. | ||
</div> | ||
</AuthLayout> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need create
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the
create
method as it was unnecessary. The POST /sign_in endpoint isn't needed since Clerk manages authentication through its own frontend flow. Changes in commit 012a1d2.