目标
我想Authorization用访问令牌填充我的标头。我想将该访问令牌存储在 Apollo 缓存中,因为Auth0明确声明不要将访问令牌存储在本地存储中(我不知道为什么Apollo 客户端文档似乎认为这是可以的)。
如果做不到这一点,我想安全地存储我的访问令牌,并能够将其添加到 Apollo 服务器的每个 Apollo 客户端请求中。
const apolloClient = withApollo(({ctx, headers, initialState}) => {
const cache = new InMemoryCache();
// Code here to access local cache.
return new ApolloClient({
cache,
link: new HttpLink({
uri: <apollo server endpoint>,
headers: {
Authorization: `Bearer ${accessToken}`,
'Access-Control-Allow-Origin': 'http://localhost:3000/',
...headers
},
credentials: 'include'
}),
typeDefs,
resolvers
})
})
class MyApp extends App {
render() {
const { Component, pageProps, apollo } = this.props;
return ( …Run Code Online (Sandbox Code Playgroud) authorization apollo server-side-rendering react-apollo next.js
下面的代码用于获取整数,每个数字的平方,并返回带有平方数字的整数.
但是,我一直有这个错误:
`square_digits': undefined method `digits' for 3212:Fixnum (NoMethodError)
from `
'
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我有这个错误,因为.digits方法是ruby中包含的方法,我在一个整数上使用它,但它给了我一个NoMethodError.
def square_digits(digit)
puts digit
puts digit.inspect
puts digit.class
if digit <= 0
return 0
else
#converts the digit into digits in array
split_digit = digit.digits
puts "split digit class and inspect"
puts split_digit.inspect
puts split_digit.class
# multiples each digit by itself
squared = split_digit.map{ |a| a * a}
squared.reverse!
# makes digits into string
string = squared.join('')
# converts string into integer
string.to_i
end
end
Run Code Online (Sandbox Code Playgroud)
有谁知道发生了什么?