将用户从我的网站重定向到移动应用程序
我在 vercel 上运行了这个中间件函数,我试图用它来重定向用户。该链接是在 Expo 上生成的,它包含指向我的应用程序的深层链接。该链接会通过电子邮件发送给用户以用于身份验证。
该链接看起来像这样
https://www.mywebsite.com/redirect?redirectUrl=exp://192.168.1.0:9000&mode=signIn&lang=en&apiKey=xxxx&oobCode=xxxx
所以我设法获取我也想定向的世博会链接,但它永远不会进入我的应用程序,因为
总是被添加到链接中,所以我最终得到
https://www.mywebsite.com/exp://192.168.1.0:9000&mode=signIn&lang=en&apiKey=xxxx&oobCode=xxxx
如何修改我的函数以直接到世博会链接?
import { NextRequest, NextResponse } from "next/server";
export default async function redirects(req, res) {
const { url } = req;
const { href, origin, searchParams } = req.nextUrl;
if (href.includes("redirectUrl")) {
let extractedUrl = url.split("?")[1];
let redirectUrl = extractedUrl.replace("redirectUrl=", "");
return NextResponse.redirect(redirectUrl);
}
return NextResponse.next();
}
I have this middleware function running on vercel that I'm attempting to redirect users with. The link is generated on Expo and it contains a deeplink to my app. This link gets emailed to the user for auth purposes.
The link looks like this
https://www.mywebsite.com/redirect?redirectUrl=exp://192.168.1.0:9000&mode=signIn&lang=en&apiKey=xxxx&oobCode=xxxx
So I manage to get the expo link I want to direct too but it never goes to my app because
always gets added to the link so I end up with
https://www.mywebsite.com/exp://192.168.1.0:9000&mode=signIn&lang=en&apiKey=xxxx&oobCode=xxxx
How can I modify my function to direct to the Expo link?
import { NextRequest, NextResponse } from "next/server";
export default async function redirects(req, res) {
const { url } = req;
const { href, origin, searchParams } = req.nextUrl;
if (href.includes("redirectUrl")) {
let extractedUrl = url.split("?")[1];
let redirectUrl = extractedUrl.replace("redirectUrl=", "");
return NextResponse.redirect(redirectUrl);
}
return NextResponse.next();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对此走了一条不同的路线。如果有人感兴趣的话,是否可以在没有中间件和常规 getInitialProps 的情况下进行重定向。
这就是我想出来的。请随意建议我如何改进这一点。
Went a different route with this. Did the redirect without the middleware and regular getInitialProps if anyone was interested.
This is what I came up with. Feel free to suggest how I can improve this.