Authentication

How do we design user login/sign up ? Does the framework include any authentication mechanisms ? How much work does it need to re-implement for social sign in and email/ password authentication.

Pakyow doesn't include any built-in mechanism for authentication at this point (this will change in the future). You can implement this through a session
object in a controller tied to a data source. Here's some example code that might help:
# backend/controllers/sessions.rb
#
require "bcrypt"
controllers :sessions, "/sessions" do
post do
user = data.users.by_email(params[:email]).one
if user.nil? || !password_matches?(params[:password], hashed_password: user.password_hash)
redirect "/login"
else
session[:user_id] = user.id
end
end
private def password_matches?(password, hashed_password:)
hash_password(password) == hashed_password
end
private def hash_password(password)
BCrypt::Password.new(matching_user.password_hash)
end
end
# backend/sources/users.rb
#
source :users do
attribute :email
attribute :password_hash
end

Thanks a lot. This helps me alot

Note that the example I provided had a typo. It should be:
controller :sessions, "/sessions" do
...
end
So: controller
instead of controllers
.

I'm trying to install pakyow, and having some trouble. I've installed ruby. https://i.gyazo.com/d1667d9cac472a9fa80daf4e58dc35fc.png https://i.gyazo.com/0ae4f03a95158d20bf9469650494be23.png

@drob: It looks like you need to install development tools on your machine. For Ubuntu, it would look like this:
sudo apt-get update
sudo apt-get install build-essential
If you continue to have trouble, can you open a new thread?
Please sign in to reply.