File tree Expand file tree Collapse file tree 3 files changed +90
-0
lines changed
snippets/appcheck-next/index Expand file tree Collapse file tree 3 files changed +90
-0
lines changed Original file line number Diff line number Diff line change @@ -63,3 +63,40 @@ function initializeCustomProvider() {
6363 } ) ;
6464 // [END appcheck_initialize_custom_provider]
6565}
66+
67+ function nonFirebase ( ) {
68+ const { initializeApp } = require ( "firebase/app" ) ;
69+ const app = initializeApp ( {
70+ // Your firebase configuration object
71+ } ) ;
72+ const { ReCaptchaV3Provider } = require ( 'firebase/app-check' ) ;
73+ const provider = new ReCaptchaV3Provider ( '' ) ;
74+
75+ // [START appcheck_nonfirebase]
76+ const { initializeAppCheck, getToken } = require ( 'firebase/app-check' ) ;
77+
78+ const appCheck = initializeAppCheck (
79+ app ,
80+ { provider : provider } // ReCaptchaV3Provider or CustomProvider
81+ ) ;
82+
83+ const callApiWithAppCheckExample = async ( ) => {
84+ let appCheckTokenResponse ;
85+ try {
86+ appCheckTokenResponse = await getToken ( appCheck , /* forceRefresh= */ false ) ;
87+ } catch ( err ) {
88+ // Handle any errors if the token was not retrieved.
89+ return ;
90+ }
91+
92+ // Include the App Check token with requests to your server.
93+ const apiResponse = await fetch ( 'https://yourbackend.example.com/yourApiEndpoint' , {
94+ headers : {
95+ 'X-Firebase-AppCheck' : appCheckTokenResponse . token ,
96+ }
97+ } ) ;
98+
99+ // Handle response from your backend.
100+ } ;
101+ // [END appcheck_nonfirebase]
102+ }
Original file line number Diff line number Diff line change @@ -53,3 +53,24 @@ function initializeCustomProvider() {
5353 appCheck . activate ( appCheckCustomProvider ) ;
5454 // [END appcheck_initialize_custom_provider]
5555}
56+
57+ // [START appcheck_nonfirebase]
58+ const callApiWithAppCheckExample = async ( ) => {
59+ let appCheckTokenResponse ;
60+ try {
61+ appCheckTokenResponse = await firebase . appCheck ( ) . getToken ( /* forceRefresh= */ false ) ;
62+ } catch ( err ) {
63+ // Handle any errors if the token was not retrieved.
64+ return ;
65+ }
66+
67+ // Include the App Check token with requests to your server.
68+ const apiResponse = await fetch ( 'https://yourbackend.example.com/yourApiEndpoint' , {
69+ headers : {
70+ 'X-Firebase-AppCheck' : appCheckTokenResponse . token ,
71+ }
72+ } ) ;
73+
74+ // Handle response from your backend.
75+ } ;
76+ // [END appcheck_nonfirebase]
Original file line number Diff line number Diff line change 1+ // This snippet file was generated by processing the source file:
2+ // ./appcheck-next/index.js
3+ //
4+ // To make edits to the snippets in this file, please edit the source
5+
6+ // [START appcheck_nonfirebase_modular]
7+ import { initializeAppCheck , getToken } from 'firebase/app-check' ;
8+
9+ const appCheck = initializeAppCheck (
10+ app ,
11+ { provider : provider } // ReCaptchaV3Provider or CustomProvider
12+ ) ;
13+
14+ const callApiWithAppCheckExample = async ( ) => {
15+ let appCheckTokenResponse ;
16+ try {
17+ appCheckTokenResponse = await getToken ( appCheck , /* forceRefresh= */ false ) ;
18+ } catch ( err ) {
19+ // Handle any errors if the token was not retrieved.
20+ return ;
21+ }
22+
23+ // Include the App Check token with requests to your server.
24+ const apiResponse = await fetch ( 'https://yourbackend.example.com/yourApiEndpoint' , {
25+ headers : {
26+ 'X-Firebase-AppCheck' : appCheckTokenResponse . token ,
27+ }
28+ } ) ;
29+
30+ // Handle response from your backend.
31+ } ;
32+ // [END appcheck_nonfirebase_modular]
You can’t perform that action at this time.
0 commit comments