特定の順序で実行したいいくつかのメソッドを連鎖させました。2 番目のメソッドdeviseLogin()
は、次のメソッドで渡す必要がある URL を返しますredirect(url)
1 番目と 2 番目のメソッドが実行されますが、最後の からは何も聞こえませんredirect(url)
。私が間違っていることがわかりますか?
getUserToken = (username, password) ->
console.log "I'm first"
$http(
method: "POST"
url: "/oauth/token"
params: params
).success((data, status, headers, config) ->
$scope.$storage.token = data.access_token
defer = $q.defer()
$scope.signIn = (data) ->
defer.promise
.then( getUserToken($scope.email, $scope.password) )
.then( deviseLogin() )
.then( redirect(url) )
redirect = (url) ->
console.log "I'm last"
console.log "will redirect to #{url}"
$window.location = data.url
deviseLogin = () ->
console.log "I'm second"
$scope.authErrors = []
authData = { user: { email: $scope.email, password: $scope.password }}
$http(
# Perform a regular Devise login
method: "POST"
url: "/users/sign_in"
data: authData
)
.success (data) ->
# I can see the log lines below and data.url is what I expect it to be
console.log "logged in devise"
console.log "data.url: #{data.url}"
data.url