richardwong
12/22/2021, 5:11 AMrichardwong
12/22/2021, 5:12 AMsandeepsihari
12/22/2021, 9:11 AMnpx wrangler pages dev -- npx next dev
sample function code here TEXTLOCAL_API_KEY
is the environment variable being added on the pages dashboard
export const onRequestPost = async ({ request }) => {
const { phone } = await request.json();
return new Response(
JSON.stringify({ phone, TEXTLOCAL_API_KEY }),
{
headers: {
"content-type": "application/json;charset=UTF-8",
},
}
);
};
This is the error message i got when i try to execute the codesandeepsihari
12/22/2021, 9:18 AMGreg Brimble | Cloudflare Pages
12/22/2021, 9:23 AMts
export const onRequestPost = async ({ request, env }) => {
const { phone } = await request.json();
return new Response(
JSON.stringify({ phone, env.TEXTLOCAL_API_KEY }),
{
headers: {
"content-type": "application/json;charset=UTF-8",
},
}
);
};
Greg Brimble | Cloudflare Pages
12/22/2021, 9:23 AMGreg Brimble | Cloudflare Pages
12/22/2021, 9:23 AMnpx wrangler pages dev --binding TEXTLOCAL_API_KEY=somevalue -- npx next dev
Greg Brimble | Cloudflare Pages
12/22/2021, 9:25 AMsandeepsihari
12/22/2021, 9:28 AMWalshy | Pages
12/22/2021, 4:56 PMGreg Brimble | Cloudflare Pages
12/22/2021, 4:56 PMWalshy | Pages
12/22/2021, 4:56 PMGreg Brimble | Cloudflare Pages
12/22/2021, 4:58 PMJosh
12/22/2021, 4:58 PMGreg Brimble | Cloudflare Pages
12/22/2021, 4:59 PMWalshy | Pages
12/22/2021, 5:00 PMWalshy | Pages
12/22/2021, 5:00 PMcoucoueoeuf
12/23/2021, 12:43 AMsandeepsihari
12/23/2021, 9:51 AM/api/send-otp
to generate and send a otp on phone number through sms/whatsapp and another /api/verify-otp
which will verify it and return a jwt token to be used in further requests.
right now i am storing the otp along with the expirationTime
inside fauna database so that i can verify the user input otp against db otp.
await dbClient.query(
q.Update(q.Ref(q.Collection("Users"), user.ref.id), {
data: {
otp,
otpExpiry,
},
})
);
Is there a better way to achieve this using KV store or Durable Objects
?Erwin
12/23/2021, 9:56 AMGreg Brimble | Cloudflare Pages
12/23/2021, 11:56 AMsandeepsihari
12/23/2021, 11:58 AMmatekosor
12/23/2021, 12:05 PMGreg Brimble | Cloudflare Pages
12/23/2021, 12:08 PMnpm install wrangler@beta
and wrangler pages dev --help
Greg Brimble | Cloudflare Pages
12/23/2021, 12:08 PMmatekosor
12/23/2021, 12:29 PMsandeepsihari
12/23/2021, 12:44 PMOTP.get("some_key")
or OTP.set("some_key", some_value)
its not clear how can i set this in localhost using wrangler@beta
like npx wrangler pages dev --binding OTP={} -- npx next dev
?Greg Brimble | Cloudflare Pages
12/23/2021, 12:48 PMwaitUntil
to send logs of requests anywhere you like, yes 🙂Greg Brimble | Cloudflare Pages
12/23/2021, 12:50 PMwrangler pages dev ./my-static-assets-folder --kv OTP
And then you access it with: env.OTP.get("some_key")
sandeepsihari
12/23/2021, 6:33 PMjose
library
import * as jose from "jose";
token = await new jose.SignJWT({ phone: "123456987" })
.setProtectedHeader({ alg: "RS256" })
.setIssuedAt()
.setIssuer(JWT_ISSUER)
.setAudience(JWT_AUDIENCE)
.setExpirationTime(JWT_EXPIRATION_TIME)
.sign(env.JWT_PRIVATE_KEY);
and as a binding i have set JWT_PRIVATE_KEY=thisisverysecureprivatekey
but getting this error