@@ -164,6 +164,128 @@ export class AppModule {}
164164// ******************
165165import { Guard } from ' @authing/guard'
166166
167+ const guard = new Guard ({
168+ appId: ' AUTHING_APP_ID'
169+ })
170+ ```
171+ :::
172+ ::::
173+
174+ ## 初始化 Guard
175+
176+ :::: tabs : options ="{ useUrlFragment: false }"
177+ ::: tab React
178+ ``` tsx
179+ // Embed.tsx
180+
181+ // React 16 / 17
182+ // 代码示例:https://github.com/Authing/Guard/tree/v5/examples/guard-react/normal/src/pages/Embed.tsx
183+ import { useGuard } from ' @authing/guard-react'
184+
185+ // React 18
186+ // 代码示例:https://github.com/Authing/Guard/tree/v5/examples/guard-react18/normal/src/pages/Embed.tsx
187+ import { useGuard , User } from ' @authing/guard-react'
188+
189+ import React , { useEffect } from ' react'
190+
191+ function Login() {
192+ const guard = useGuard ()
193+
194+ useEffect (() => {
195+ // 使用 start 方法挂载 Guard 组件到你指定的 DOM 节点,登录成功后返回 userInfo
196+ guard .start (' #authing-guard-container' ).then ((userInfo : User ) => {
197+ console .log (' userInfo: ' , userInfo )
198+ })
199+ }, [])
200+
201+ return (
202+ <div id = " authing-guard-container" ></div >
203+ );
204+ }
205+ ```
206+ :::
207+
208+ ::: tab Vue2
209+ ``` html
210+ <div id =" authing-guard-container" ></div >
211+ ```
212+ ``` javascript
213+ // 代码示例:https://github.com/Authing/Guard/tree/v5/examples/guard-vue2/normal/src/views/Embed.vue
214+ // Embed.vue
215+ export default {
216+ mounted () {
217+ // 使用 start 方法挂载 Guard 组件到你指定的 DOM 节点,登录成功后返回 userInfo
218+ this .$guard .start (' #authing-guard-container' ).then (userInfo => {
219+ console .log (' userInfo in start: ' , userInfo)
220+ })
221+ }
222+ }
223+ ```
224+ :::
225+
226+ ::: tab Vue3
227+ ``` html
228+ <div id =" authing-guard-container" ></div >
229+ ```
230+ ``` typescript
231+ // 代码示例:https://github.com/Authing/Guard/tree/v5/examples/guard-vue3/normal/src/views/Embed.vue
232+ // Embed.vue
233+ import { ref , onMounted } from ' vue'
234+
235+ import { useGuard } from ' @authing/guard-vue3'
236+
237+ import type { User , RefreshToken , AuthenticationClient } from ' @authing/guard-vue3'
238+
239+ const guard = useGuard ()
240+
241+ onMounted (() => {
242+ // 使用 start 方法挂载 Guard 组件到你指定的 DOM 节点,登录成功后返回 userInfo
243+ guard .start (' #authing-guard-container' ).then ((user : User ) => {
244+ console .log (" userInfo: " , user )
245+ })
246+ })
247+ ```
248+ :::
249+
250+ ::: tab Angular
251+ ``` html
252+ <div id =" authing-guard-container" ></div >
253+ ```
254+
255+ ``` typescript
256+ // 代码示例:https://github.com/Authing/Guard/blob/v5/examples/guard-angular/normal/src/app/pages/embed/embed.component.ts
257+ import { Component } from ' @angular/core'
258+
259+ import { GuardService , User } from ' @authing/guard-angular'
260+
261+ @Component ({
262+ selector: ' embed-container' ,
263+ templateUrl: ' ./embed.component.html' ,
264+ styleUrls: [' ./embed.component.css' ]
265+ })
266+ export class EmbedComponent {
267+ constructor (
268+ private guard : GuardService ,
269+ ) {}
270+
271+ ngOnInit() {
272+ // 使用 start 方法挂载 Guard 组件到你指定的 DOM 节点,登录成功后返回 userInfo
273+ this .guard .client .start (' #authing-guard-container' ).then ((userInfo : User ) => {
274+ console .log (userInfo )
275+ })
276+ }
277+ }
278+
279+ ```
280+ :::
281+
282+ ::: tab JavaScript
283+ ``` js
284+ // ******************
285+ // 所有 API 均可通过实例化 `Guard` 调用,后续不再赘述。
286+ // ******************
287+ import { Guard } from ' @authing/guard'
288+
167289const guard = new Guard ({
168290 appId: ' AUTHING_APP_ID'
169291})
0 commit comments