인증이 실패했을 때 다른 URL로 리다이렉트하고 싶습니다.
방법이 있으면 알려주시면 감사하겠습니다!
plugins
myplugin
lib
auth
my_auth_controller.rb
def after_authenticate(auth_hash)
if not auth
redirect_to "https://example.com"
end
result = Auth::Result.new
end
- 코드에는 if not auth 조건이 있지만, 이에 대응하는 else문이 없습니다.
- redirect_to 메서드는 컨트롤러 액션 내에서 사용되어야 합니다. after_authenticate와 같은 별도의 메서드에서 사용하는 경우, 컨트롤러의 범위 내에서 호출되고 있는지 확인하십시오.
따라서 올바른 코드는 다음과 같습니다.
def after_authenticate(auth_hash)
if not auth
redirect_to "https://example.com"
else
# Authentication succeeded, continue with the authentication process
result = Auth::Result.new
end
end
결과적으로, 인증에 실패하면 auth가 true가 아니므로 "https://example.com"으로 리다이렉트됩니다. 반대로, 인증에 성공하면 인증 프로세스를 계속 진행합니다.
확인하려면 브라우저 개발자 도구를 사용하여 네트워크 요청과 리다이렉트를 검사하거나, redirect checker와 같은 온라인 도구를 사용할 수 있습니다. 이를 통해 리다이렉션 문제와 상태 코드를 식별하는 데 도움이 됩니다.