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

Request to fix (#117), user cannot sign out during create_profile sec… #118

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/routes/(admin)/account/create_profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
<div class="text-sm text-slate-800 mt-14">
You are logged in as {session?.user?.email}.
<br />
<a class="underline" href="/account/sign_out"> Sign out </a>
<form action="/account/sign_out" method="POST">
<button type="submit" class="underline">Sign out</button>
</form>
Comment on lines +116 to +118
Copy link

@coderabbitai coderabbitai bot Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation of sign-out using a form.

The use of a form with a POST method for signing out aligns with best practices. Ensure that any errors during form submission are handled and communicated to the user.

<form action="/account/sign_out" method="POST">
  <button type="submit" class="underline">Sign out</button>
  <!-- Consider adding error handling for the form submission -->
</form>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use the sign out link format we use elsewhere:

<a href="/account/sign_out" class="link">Sign Out</a>

No need to add a new endpoint.

POST does make sense, but don't want to fragment it and have a mix of methods across the template.

Sounds good?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scosman, that makes sense. Consistency across the application is important, and using the same sign-out link format helps maintain that. Reverting to the anchor tag format as used elsewhere is a good approach. Let me know if there's anything else you'd like to adjust!

Copy link
Author

@ericpb ericpb Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the preference for consistency. However the current approach of using
<a href="/account/sign_out" class="link">Sign Out</a>
is not working on the create_profile page. I think due to the differences in how SvelteKit handles page navigation between layouts and individual pages.
I'm quite new to SvelteKit and this template so I could be wrong; happy to discuss further.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

</div>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/routes/(admin)/account/sign_out/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { redirect } from "@sveltejs/kit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just delete this change (see above comment)


export const actions = {
default: async ({ locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession()
if (session) {
await supabase.auth.signOut()
}
redirect(303, "/")
Comment on lines +4 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for the sign-out operation.

Currently, the signOut operation does not handle potential errors. Consider adding error handling to ensure robustness.

export const actions = {
  default: async ({ locals: { supabase, safeGetSession } }) => {
    const { session } = await safeGetSession()
    if (session) {
      try {
        await supabase.auth.signOut()
      } catch (error) {
        console.error("Error signing out:", error)
        // Optionally, handle the error by redirecting to an error page or displaying a message
      }
    }
    redirect(303, "/")
  },
}

},
}
Loading