如何解决Hotwire rails 应用程序:重定向到外部服务失败
我正在将 discourse 单点登录与 hotwire rails 应用程序集成,一切正常,直到重定向,当它重定向时,我看到有 CORS 问题浏览器,当然它的 turbo 请求,所以它尝试从给定的 URL 获取响应它引发 CORS 错误,我们如何在此处进行实际重定向?。
def sso
secret = "572890bb92bbef8c4634c1bf"
sso = SingleSignOn.parse(request.query_string,secret)
sso.email = current_user.email # from devise
sso.name = current_user.name # this is a custom method on the User class
sso.username = current_user.username # from devise
sso.external_id = current_user.id # from devise
sso.sso_secret = secret
redirect_to sso.to_url("https://xxxxxxxx/session/sso_login")
end
编辑(1)
<main class="main-content">
<div class="d-flex justify-content-center">
<div>
<div class="mt-48 py-48 px-md-48 px-32 border-radius-lg log-in-card Box-shadow-05">
<h4 class="font-size-24 text-black font-weight-400 mb-0">Member Login</h4>
<%= form_for(resource,as: resource_name,url: session_path(resource_name),html: {class: 'mt-48'}) do |f| %>
<div class="form-group mb-0">
<%= f.label :email,class: "font-weight-500 font-size-14 text-black" %>
<%= f.email_field :email,autofocus: true,autocomplete: "email",class: 'form-control-lg form-control' %>
</div>
<div class="form-group position-relative mt-32">
<%= f.label :password,class: "font-weight-500 font-size-14 text-black" %>
<%= f.password_field :password,autocomplete: "current-password",class: 'form-control-lg form-control' %>
<div class="position-absolute eye-icon"><i class="far fa-eye-slash font-size-14 text-black"></i></div>
</div>
<div class="d-flex flex-column align-items-center mt-32">
<%= f.submit "Login",class: 'btn btn-brand-primary py-12 px-48 text-decoration-none' %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forget password?",new_password_path(resource_name),class: 'text-decoration-none text-brand-primary font-weight-600 font-size-14 mt-32' %>
<% end %>
</div>
<% end %>
</div>
<div class="d-flex justify-content-center mt-48">
<span class="text-black font-weight-500 font-size-14 text-decoration-none">Not a member?</span>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Create Account",new_registration_path(resource_name),class: 'text-brand-primary font-weight-600 font-size-14 text-decoration-none ml-8' %>
<% end %>
</div>
<div class="d-flex flex-md-row flex-column align-items-center justify-content-center mt-48 mb-96 pb-md-64">
<span class="text-black font-weight-500 font-size-14 text-decoration-none">Didn't receive confirmation
instructions?</span>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Request again",new_user_confirmation_path(resource_name),class: 'text-brand-primary font-weight-600 font-size-14 text-decoration-none ml-8'%>
<% end %>
</div>
</div>
</div>
</main>
解决方法
我在登录表单中使用了 data-turbo="false"
,它会将 HTML 请求发送到后端,因为当我进行重定向时,它会重定向整个页面。谢谢
https://turbo.hotwire.dev/handbook/drive#disabling-turbo-drive-on-specific-links-or-forms
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。