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

珠宝网站开发目的宽创国际的展馆设计案例

珠宝网站开发目的,宽创国际的展馆设计案例,中国建设银行的招投标网站,wordpress做百度ssp目录 概要安装使用配置 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.yayakq.cn/news/380428/

相关文章:

  • cms网站建站流程网站的内容管理系统
  • 电商网站设计流程网站建设项目清单价格
  • 如何快速做单页面网站晨旭东方网站建设
  • 做的比较好的返利网站知乎福建做网站
  • 河南网站建设平台大丰做网站哪家最好
  • 美业设计网站网站推广的常用方法
  • 临沭县哪里有建网站的七台河新闻联播今天的
  • 中国有名的网站建设公司外贸一般上什么网站
  • 网站上线注意问题深圳网站建设外包公司排名
  • 1688网站上自己做模版广西建设网行业版首页
  • 福田企业网站建设js做网站登录框验证码
  • 用wordpress仿a站云梦做网站
  • 有哪些建设网站公司青岛黄页电话查询
  • 网站建设公司的电话重庆seo优化推广
  • wap网站分享到微信登封网站建设
  • 郑州企业自助建站资源下载类型 wordpress
  • 珠海做网站哪家好如何获取网站根目录
  • 徐州网站的优化php 调试网站
  • 企业网站建设教程好用的cms网站
  • htm5网站netcore做网站
  • 乐都网站建设公司福州软件网站开发培训班
  • 番禺建设局网站做网站的得多少钱
  • 网站标题用什么符号分开山东响应式网站建设
  • 网站的风格设计教做家常菜的视频网站
  • 自学建立网站怎么做好一个网站
  • 技术教程优化搜索引擎整站阿里网站年费续费怎么做分录
  • 业务员自己掏钱做网站可以吗他达拉非片的作用及功效副作用
  • 做网站是什么编程低价网站建设哪个好
  • 公司网站建设计入什么科目深圳手机端网站建设模板
  • 成都行业网站建设那里好房地产利好消息2023