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

Suggestion: Don't sign in the user on first signup call #17

Open
Tyler-Keith-Thompson opened this issue Dec 2, 2024 · 0 comments
Open

Comments

@Tyler-Keith-Thompson
Copy link

First off, thank you for putting this together! It was very helpful for me. On the signup route it currently does:
req.auth.login(user) so that GET:makeCredential and POST:makeCredential know which user is signed in.

When I was adapting the example this caused a side effect where if the user abandoned the sign up flow it'd cause them to be "logged in", which had somewhat hilarious consequences for my site.

I ended up switching this to try req.session.data["userID"] = user.requireID().uuidString and then in later places where I needed it:

guard let idString = req.session.data["userID"],
                  let id = UUID(uuidString: idString),
                  let user = try await User.find(id, on: req.db) else {
                throw Abort(.unauthorized)
            }

Which solved my issue. I figured I'd share in case anybody else was trying to adapt this example into something production ready or in case there was a better way or something I hadn't considered about my alternative.

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

1 participant