当前位置: 首页 > news >正文

今日生猪价格表如何优化网络延迟

今日生猪价格表,如何优化网络延迟,wordpress 文章中图片居中,微信怎么推广最有效目录 概要安装使用配置 Remix Auth配置登录跳转配置 callback 回调配置 Demo 测试页配置注销登录 概要 爱发电 OAuth 文档: https://afdian.net/p/010ff078177211eca44f52540025c377 注意一下这里有两个细节: 这里的 OAuth 非标准化 OAuth&#xff0c…

目录

  • 概要
  • 安装使用
    • 配置 Remix Auth
    • 配置登录跳转
    • 配置 callback 回调
    • 配置 Demo 测试页
    • 配置注销登录

概要

爱发电 OAuth 文档: https://afdian.net/p/010ff078177211eca44f52540025c377

注意一下这里有两个细节:

  1. 这里的 OAuth 非标准化 OAuth,没有 AccessToken
  2. 申请和维护没有管理界面,需要给管理员发送私信

代码仓库: https://github.com/willin/remix-auth-afdian

在线演示: https://remix-auth-afdian.willin.wang/

安装使用

包名: remix-auth-afdian

npm i --save remix-auth-afdian
# or
pnpm i remix-auth-afdian
# or
yarn add remix-auth-afdian

配置 Remix Auth

在项目根目录下创建一个 auth.server.ts 代码文件:

import { createCookieSessionStorage, type ActionFunctionArgs } from '@remix-run/cloudflare';
import { Authenticator } from 'remix-auth';
import { AfdianStrategy } from 'remix-auth-afdian/build/index';export function getAuthenticator({ context, request }: ActionFunctionArgs) {const url = new URL(request.url);url.pathname = '/auth/afdian/callback';const sessionStorage = createCookieSessionStorage({cookie: {name: 'sid',httpOnly: true,secure: context.env.CF_PAGES === 'production',sameSite: 'lax',path: '/',secrets: ['s3cr3t']}});const authenticator = new Authenticator(sessionStorage, {throwOnError: true});const afdianStrategy = new AfdianStrategy({clientID: context.env.AFDIAN_CLIENT_ID,clientSecret: context.env.AFDIAN_CLIENT_SECRET,callbackURL: url.toString()},async ({ accessToken, extraParams, profile }) => {return profile;});authenticator.use(afdianStrategy);return authenticator;
}

替换其中的配置,如:

  • @remix-run/cloudflare 根据需要,切换 Remix 运行环境
  • callback url 回调的地址
  • session 配置
  • client 相关信息,id 及密钥

配置登录跳转

创建 auth.afdian.tsx 文件:

import { type ActionFunctionArgs, redirect } from "@remix-run/cloudflare";
import { getAuthenticator } from "~/auth.server";export async function loader() {return redirect("/");
}export async function action(args: ActionFunctionArgs) {const authenticator = getAuthenticator(args);return await authenticator.authenticate("afdian", args.request, {successRedirect: "/dashboard",});}

注意:该文件命名采用的是 remix v2 规则,v1 的话用目录分隔。

配置 callback 回调

创建 auth.afdian.callback.tsx 文件:

import { getAuthenticator } from '~/auth.server';export async function loader(args) {const authenticator = getAuthenticator(args);return authenticator.authenticate('afdian', args.request, {successRedirect: '/dashboard',failureRedirect: '/'});
}

这样已经大功告成了。

配置 Demo 测试页

比如这里叫 dashboard.tsx 页面:

import { json, redirect } from '@remix-run/cloudflare';
import { Form, useLoaderData } from '@remix-run/react';
import { getAuthenticator } from '~/auth.server';export async function loader(args) {const authenticator = getAuthenticator(args);const user = await authenticator.isAuthenticated(args.request);if (!user) {throw redirect('/');}return json(user);
}export default function Page() {const data = useLoaderData<typeof loader>();return (<div><h1>已登录 Logged in</h1><p><Form action='/api/logout' method='POST'><button>Logout</button></Form></p><pre>{JSON.stringify(data, null, 2)}</pre></div>);
}

配置注销登录

import { type LoaderFunction, type ActionFunction, redirect } from '@remix-run/cloudflare';
import { getAuthenticator } from '~/auth.server';export const loader: LoaderFunction = () => {return redirect('/');
};export const action: ActionFunction = async (args) => {const { request } = args;const authenticator = getAuthenticator(args);const referer = request.headers.get('referer');const returnPath = referer ? new URL(referer).pathname : '/';return await authenticator.logout(request, {redirectTo: returnPath});
};

这个可以根据需要添加。

如果您对爱发电感兴趣,想要让其支持更多的框架。可以联系我进行定制开发。

打赏地址:https://afdian.net/a/willin

感谢您的观看~

http://www.tj-hxxt.cn/news/96022.html

相关文章:

  • 建设网站明细报价表经典软文案例100例简短
  • 怎么做微信小说网站吗淘宝如何刷关键词增加权重
  • 什么网站没人做吸引人气的营销方案
  • 自己做网站要不要租服务器杭州百度推广优化排名
  • 卢松松的网站最佳搜索引擎磁力王
  • 舒城县建设局网站首页网站排名怎么做
  • 一级a做爰片免费网站 新闻公众号推广接单平台
  • 织梦cms官方网站湘潭关键词优化服务
  • 江苏 网站集约化建设方案seo网络营销推广公司
  • 图片存放网站做链接谷歌外贸平台叫什么
  • 服务器网站过多对排名百度客服电话人工服务热线
  • 唯品会 一家专做特卖的网站运营商大数据精准营销获客
  • 网站开发的实训内容今天重大新闻头条新闻
  • 青岛有做网站的吗网站推广的途径和方法
  • 石家庄网站系统开发电商运营培训班多少钱
  • 网站服务器权限网站优化推广服务
  • 做化妆品的一些网站网站单向外链推广工具
  • 在建项目经理查询做网站怎么优化
  • 做代收的网站有哪些广东seo快速排名
  • 源码网站跟自己做的网站区别全国前十名小程序开发公司
  • 广州网站改版 网站建设建网站设计
  • 手机端怎样做网站建设网站优化排名资源
  • 双桥区网站制作成crm软件
  • 永久免费的ppt网站在线培训平台哪家好
  • 网站建设公司格seo优化培训公司
  • 网站设计什么样风格会高端些网络网站推广选择乐云seo
  • 深圳专业专业网站设计营销网站建设价格
  • 香港网站域名申请产品如何做市场推广
  • 松江营销型网站建设公司百度一下网页版浏览器百度
  • 医院建设官方网站必要性南阳本地网络推广优化公司