- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
TLDR
header authorization
没有随 apollo 一起发送。这导致 You do not have the appropriate capabilities to perform this action
const apolloClient = ({ cookies: { token = null }, headers }) => {
const authLink = setContext(_ => {
console.info(token) //correct tokens
return {
headers: {
...headers,
authorization: `Bearer ${token}`,
},
}
})
return new ApolloClient({
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
console.error(graphQLErrors, networkError)
}),
authLink.concat(
createHttpLink({
uri: graphQL,
credentials: 'same-origin',
fetch: fetch,
})
),
]),
cache: new InMemoryCache(),
})
}
nextjs lamba
文件之一中对自己进行身份验证,该文件现在位于
/pages/api/*
中
apollo.serverless.js
文件,它被导入到我进行数据库交互的
pages/api/users/update/role/[userId].js
中。
req
into
apollo.serverless.js`,以便我可以访问 cookie 中的不记名 token 。
http://localhost:3000/api/users/update/role/dXNlcjoxMTg=
因为 strip webhook 将使用查询参数直接访问此 url。
import { useQuery, useMutation } from '../../../../../lib/apollo/apollo.serverless'
import { updateMemberRole, allUsers } from '../../../queries/users'
export default async (req, res) => {
let data
try {
const mutationInfo = await useMutation(
{
mutation: updateMemberRole,
variables: {
userId: req.query.userId,
},
},
req
)
data = mutationInfo.data
} catch (err) {
data = err
}
res.status(200).json({ data })
}
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,en-GB;q=0.8,fr;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Cookie: analyticsCookieAccepted=1; analyticsCookieNoticeClosed=1; _ga=GA1.1.2044509544.1574855120; wordpress_test_cookie=WP+Cookie+check; OPTOUTMULTI=0:0%7Cc4:0%7Cc3:0%7Cc2:0; wp-settings-45=editor%3Dhtml%26libraryContent%3Dbrowse%26imgsize%3Dfull; wp-settings-time-45=1575018303; theme=light; wp-settings-time-1=1575496501; utag_main=v_id:016eacdb7ad1001fa3af49cf1fec01069001606100fb8$_sn:18$_se:1$_ss:1$_st:1575891251585$ses_id:1575889451585%3Bexp-session$_pn:1%3Bexp-session; wordpress_logged_in_86a9106ae65537651a8e456835b316ab=glasshousegames%7C1578351721%7CtL4KMHIW7tTAUuCzUOJd8r6Mu5buST9mheH2tn9WFQs%7C593e133b11f6c0745f577e32d66db0cf1ccfa012504f9015fc64c515d2df77d2; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJpYXQiOjE1NzgwNTgyOTIsIm5iZiI6MTU3ODA1ODI5MiwiZXhwIjoxNTc4NjYzMDkyLCJkYXRhIjp7InVzZXIiOnsiaWQiOiIxMTgifX19.iMSh4KjuON3otpOqO3TXpYAh2bQYu48sqm9pzsgeBis
Host: localhost:3002
Pragma: no-cache
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
import dotenv from 'dotenv'
import { fetch } from 'cross-fetch/polyfill'
import { createHttpLink } from 'apollo-link-http'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context'
import { onError } from 'apollo-link-error'
import { ApolloLink } from 'apollo-link'
import { graphQL } from 'app.config'
import ApolloClass, { sortParams } from '~/lib/apollo/apollo.class'
dotenv.config()
const apolloClient = ({ cookies: { token = null }, headers }) => {
const authLink = setContext(_ => {
return {
headers: {
...headers,
authorization: `Bearer ${token}`,
},
}
})
return new ApolloClient({
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) => console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`))
if (networkError) console.log(`[Network error]: ${networkError}`)
}),
authLink.concat(
createHttpLink({
uri: graphQL,
credentials: 'same-origin',
fetch: fetch,
})
),
]),
cache: new InMemoryCache(),
})
}
export const useQuery = async function(query) {
const { options = {} } = sortParams([...arguments])
const { loading, data: queryData, error, ...props } = await apolloClient.query({
query,
...options,
})
let transformData = {}
if (queryData) transformData = new ApolloClass(queryData).start()
return {
queryData,
error,
loading,
data: transformData,
}
}
export const useMutation = async function(mutation, req) {
const { data } = await apolloClient(req).mutate(mutation)
return { data }
}
// 20200106132714
// http://localhost:3002/api/users/update/role/dXNlcjoxMTg=
{
"data": {
"graphQLErrors": [
{
"message": "You do not have the appropriate capabilities to perform this action",
"category": "user",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"updateUser"
]
}
],
"networkError": null,
"message": "GraphQL error: You do not have the appropriate capabilities to perform this action"
}
}
http://localhost:3000/api/users/update/role/cm9sZTpzdGFuZGFyZA==
时我在 header 中看不到它们
Bearer SomeToken
,所以我确信一旦发送 token ,一切正常。 JWT 在我与 cookie 的所有交互中都能正常工作。
RewriteCond %{HTTP:Authorization} ^(.)
RewriteRule ^(.) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<ifmodule mod_headers.c="">
# SetEnvIf Origin "^(.*\.domain\.com)$" ORIGIN_SUB_DOMAIN=$1
SetEnvIf Origin "http(s)?://(www\.)?(localhost|now.sh|dev.domain1.games)$" ORIGIN_SUB_DOMAIN=$1
Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN
Header set Access-Control-Allow-Methods: "*"
Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, Authorization, Content-Disposition"
</ifmodule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
</IfModule>
最佳答案
将此添加到您的 .htaccess 文件中
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
关于javascript - Apollo 客户端未在 Nextjs Lamda 中发送 JWT 不记名 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59543955/
zeta 在 critic 方法中代表什么?我相信它会跟踪状态- Action 对并表示资格跟踪,这是状态- Action 的临时记录,但 zeta 究竟代表什么以及它在 C++ 中的外观如何(例如
我想列出一个方法调用的所有方法。 void create() throws MyException { System.out.println("TEST"); of("String")
所以我只是在玩 kotlin,无法解决这个问题。 fun itsAfunction() = 10 fun check(function:()->Int):Int{ re
想知道是否可以让网络应用程序将文件 (userid.input.json) 上传到 Amazon S3,这会触发一个 lambda 函数来读取文件、进行一些处理并保存结果作为另一个 (userid.o
假设我有一个包含 Button 和 Spinbox 的 Widget。单击按钮时,我希望发出 Spinbox 的值。 我看到了两种可能的方法: 要么我可以创建一个私有(private)成员函数 //.
java 8 lamda Stream的Collectors.toMap 参数 使用toMap()函数之后,返回的就是一个Map了,自然会需要key和value。 toMap()的第一个参数就是用来生
fun theItemDTO.toDomainModel( domainOrderId: String, pIds: List = emptyList() ): theItem = l
我有一个 android 项目,它依赖于一个库模块。我的模块中有一个这样的接口(interface): public interface SimpleAnimationListener exte
我有getter方法 @JsonInclude(Include.NON_NULL) public Date getVerifiedFrom() { if(invoices == null ||
假设,我有一个卷积层的 10x10x4 中间输出,我需要将其分成 100 个 1x1x4 卷,并对每个卷应用 softmax,以获得 100 个输出网络。有没有办法在不使用 Lambda 层的情况下完
我写了这样的 JavaFX 摆弄: MenuItem menuItem1 = new MenuItem("Item 1") menuItem1.setOnAction(e -> {
我在研究 lambda 表达式时遇到了这个问题: #include using std::cout; int main() { auto lam = [](int a){ cout #inc
考虑下面的模板函数 sort(...)。这是一个围绕 std::sort 的包装函数。目的是在对用户定义类的 vector 进行排序时提供更好的语法。第一个参数是要排序的 vector 。第二个参数是
TLDR header authorization 没有随 apollo 一起发送。这导致 You do not have the appropriate capabilities to perfor
我在 API 网关之后使用 NodeJs Lambda。 var AWS = require('aws-sdk'); const cognito = new AWS.CognitoIdentitySe
我每天晚上 8 点使用 chalice 和 lambda 函数安排 ec2 实例关闭。 我已经配置了 chalice ,但无法使用 chalice 触发或集成 python 脚本 导入 boto3 #
我正在学习 Java 8 中的 Lambda 表达式和方法引用,发现我们可以通过使用“super”来引用方法的父类(super class)版本,如: super ::名称 但是当我这样做时,它不起作
如何将 CommaDelimitedList 参数转换为字符串,以便将其作为环境变量传递给 Lamda 函数? 下面是示例 CommaDelimitedList 参数,其中包含 AWS 区域列表,我需
我使用的第三方 API 返回一个类型为 int[] 的数组。我们将其称为 readWords: int[] readWords 然而,这个重新调整的数组应该是一个 uint[]。所以我正在进行以下转换
我是一名优秀的程序员,十分优秀!