[英]How to verify user email while using GraphQl and Node.js
我正在嘗試使用GraphQL和Node.js在我的寵物項目中實施用戶電子郵件驗證。
我已經有了signUp解析器來發送驗證令牌,但是我剛剛了解到,當用戶單擊鏈接時,無法將數據從電子郵件發送到下一個使用該令牌並驗證電子郵件的GraphQL解析器。
所以問題是:我應該讓REST端點/verify
來完成工作,還是可以使用/graphql
端點
如果您使用單獨的/verify
端點,則很可能在處理請求后也希望將用戶重定向回您的站點。 一種方法是有效逆轉此流程,鏈接到您的網站,然后讓您的頁面提出必要的GraphQL請求。
或者,您可以通過電子郵件中的鏈接調用verify
解析器。 express-graphql
將同時處理POST
和GET
請求。 但是,使用此方法時需要牢記以下幾點:
這是一個基本示例:
const typeDefs = `
type Query {
verify: Boolean # Can be any nullable scalar
}
`
const resolvers = {
Query: {
verify: (root, args, ctx) => {
// Your verification logic
ctx.res.redirect('https://www.google.com')
}
}
}
const schema = makeExecutableSchema({ typeDefs, resolvers })
app.use('/graphql', graphqlHTTP((req, res) => ({
schema: MyGraphQLSchema,
graphiql: false,
// Inject the response object into the context
context: { req, res },
})))
app.listen(4000)
然后,您可以在瀏覽器中導航至以下網址:
http://localhost:4000/graphql?query={verify}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.