我有一个提供API的Elixir后端。我的SPA是由Vue.js支持的。我需要在Elixir中实现一个简单的用户登录系统。我发现了很多使用Guardian的例子,但每个人都在使用Phoenix作为框架。有没有人能给我举个不用Phoenix的例子?使用其他库的示例也很受欢迎
发布于 2017-05-11 19:05:53
一切都取决于你想要什么样的身份验证,以及你如何与Elixir后端通信。假设你有一个运行在某种and服务器上的Elixir,你所需要的就是在后端和前端之间有一个接口。
# function that checks whether user is authenticated
def authenticate(user, password) do
password_hash = give_me_password_hash_for_user(user)
# how you want to retrieve that - maybe Ecto? Ecto is not a part of Phoenix
if Comeonin.Bcrypt.checkpw(password, password_hash) do # using here Comeonin
happy_path()
else
unauthorized_path()
end
end当然,您还需要传递用户登录的信息-将其保存在会话中,或者将令牌(jwt或Phoenix )发送到每个API调用。
https://stackoverflow.com/questions/43913020
复制相似问题