1- import type { ClaimTokenType , FlagType } from '@kinde-oss/kinde-typescript-sdk'
1+ /**
2+ * This file contains routes and sample routes for possible APIs usecases with Kinde.
3+ */
4+
5+ // import type { ClaimTokenType, FlagType } from '@kinde-oss/kinde-typescript-sdk'
26import { appFactory } from '#src/helpers/factory.js'
37import { getSessionManager } from '#src/helpers/kinde.js'
48import { getKindeClient } from '#src/providers/auth/kinde-main.js'
@@ -9,6 +13,18 @@ export const authRoutesApp = appFactory.createApp()
913 return c . text ( 'Good' , 200 )
1014 } )
1115
16+ . get ( '/authState' , async ( c ) => {
17+ const kindeClient = await getKindeClient ( )
18+ const sessionManager = getSessionManager ( c )
19+
20+ const [ profile , token ] = await Promise . all ( [
21+ kindeClient . getUserProfile ( sessionManager ) . catch ( ( ) => null ) ,
22+ kindeClient . getToken ( sessionManager ) . catch ( ( ) => null ) ,
23+ ] )
24+
25+ return c . json ( { profile, token } )
26+ } )
27+
1228 . get ( '/login' , async ( c ) => {
1329 const kindeClient = await getKindeClient ( )
1430 const org_code = c . req . query ( 'org_code' )
@@ -49,92 +65,92 @@ export const authRoutesApp = appFactory.createApp()
4965 return c . redirect ( logoutUrl . toString ( ) )
5066 } )
5167
52- . get ( '/isAuth' , async ( c ) => {
53- const kindeClient = await getKindeClient ( )
68+ // .get('/isAuth', async (c) => {
69+ // const kindeClient = await getKindeClient()
5470
55- const isAuthenticated = await kindeClient . isAuthenticated ( getSessionManager ( c ) ) // Boolean: true or false
71+ // const isAuthenticated = await kindeClient.isAuthenticated(getSessionManager(c)) // Boolean: true or false
5672
57- return c . json ( isAuthenticated )
58- } )
73+ // return c.json(isAuthenticated)
74+ // })
5975
60- . get ( '/profile' , async ( c ) => {
61- const kindeClient = await getKindeClient ( )
76+ // .get('/profile', async (c) => {
77+ // const kindeClient = await getKindeClient()
6278
63- const profile = await kindeClient . getUserProfile ( getSessionManager ( c ) )
79+ // const profile = await kindeClient.getUserProfile(getSessionManager(c))
6480
65- return c . json ( profile )
66- } )
81+ // return c.json(profile)
82+ // })
6783
68- . get ( '/createOrg' , async ( c ) => {
69- const kindeClient = await getKindeClient ( )
70- const org_name = c . req . query ( 'org_name' ) ?. toString ( )
84+ // .get('/createOrg', async (c) => {
85+ // const kindeClient = await getKindeClient()
86+ // const org_name = c.req.query('org_name')?.toString()
7187
72- const createUrl = await kindeClient . createOrg ( getSessionManager ( c ) , { org_name } )
88+ // const createUrl = await kindeClient.createOrg(getSessionManager(c), { org_name })
7389
74- return c . redirect ( createUrl . toString ( ) )
75- } )
90+ // return c.redirect(createUrl.toString())
91+ // })
7692
77- . get ( '/getOrg' , async ( c ) => {
78- const kindeClient = await getKindeClient ( )
93+ // .get('/getOrg', async (c) => {
94+ // const kindeClient = await getKindeClient()
7995
80- const org = await kindeClient . getOrganization ( getSessionManager ( c ) )
96+ // const org = await kindeClient.getOrganization(getSessionManager(c))
8197
82- return c . json ( org )
83- } )
98+ // return c.json(org)
99+ // })
84100
85- . get ( '/getOrgs' , async ( c ) => {
86- const kindeClient = await getKindeClient ( )
101+ // .get('/getOrgs', async (c) => {
102+ // const kindeClient = await getKindeClient()
87103
88- const orgs = await kindeClient . getUserOrganizations ( getSessionManager ( c ) )
104+ // const orgs = await kindeClient.getUserOrganizations(getSessionManager(c))
89105
90- return c . json ( orgs )
91- } )
106+ // return c.json(orgs)
107+ // })
92108
93- . get ( '/getPerm/:perm' , async ( c ) => {
94- const kindeClient = await getKindeClient ( )
109+ // .get('/getPerm/:perm', async (c) => {
110+ // const kindeClient = await getKindeClient()
95111
96- const perm = await kindeClient . getPermission ( getSessionManager ( c ) , c . req . param ( 'perm' ) )
112+ // const perm = await kindeClient.getPermission(getSessionManager(c), c.req.param('perm'))
97113
98- return c . json ( perm )
99- } )
114+ // return c.json(perm)
115+ // })
100116
101- . get ( '/getPerms' , async ( c ) => {
102- const kindeClient = await getKindeClient ( )
117+ // .get('/getPerms', async (c) => {
118+ // const kindeClient = await getKindeClient()
103119
104- const perms = await kindeClient . getPermissions ( getSessionManager ( c ) )
120+ // const perms = await kindeClient.getPermissions(getSessionManager(c))
105121
106- return c . json ( perms )
107- } )
122+ // return c.json(perms)
123+ // })
108124
109- // Try: /api/auth/getClaim/aud, /api/auth/getClaim/email/id_token
110- . get ( '/getClaim/:claim' , async ( c ) => {
111- const kindeClient = await getKindeClient ( )
112- const type = ( c . req . query ( 'type' ) ?? 'access_token' ) as ClaimTokenType
125+ // // Try: /api/auth/getClaim/aud, /api/auth/getClaim/email/id_token
126+ // .get('/getClaim/:claim', async (c) => {
127+ // const kindeClient = await getKindeClient()
128+ // const type = (c.req.query('type') ?? 'access_token') as ClaimTokenType
113129
114- if ( ! / ^ (?: a c c e s s _ t o k e n | i d _ t o k e n ) $ / . test ( type ) )
115- return c . text ( 'Bad request: type' , 400 )
130+ // if (!/^(?:access_token|id_token)$/.test(type))
131+ // return c.text('Bad request: type', 400)
116132
117- const claim = await kindeClient . getClaim ( getSessionManager ( c ) , c . req . param ( 'claim' ) , type )
118- return c . json ( claim )
119- } )
133+ // const claim = await kindeClient.getClaim(getSessionManager(c), c.req.param('claim'), type)
134+ // return c.json(claim)
135+ // })
120136
121- . get ( '/getFlag/:code' , async ( c ) => {
122- const kindeClient = await getKindeClient ( )
137+ // .get('/getFlag/:code', async (c) => {
138+ // const kindeClient = await getKindeClient()
123139
124- const claim = await kindeClient . getFlag (
125- getSessionManager ( c ) ,
126- c . req . param ( 'code' ) ,
127- c . req . query ( 'default' ) ,
128- c . req . query ( 'flagType' ) as keyof FlagType | undefined ,
129- )
140+ // const claim = await kindeClient.getFlag(
141+ // getSessionManager(c),
142+ // c.req.param('code'),
143+ // c.req.query('default'),
144+ // c.req.query('flagType') as keyof FlagType | undefined,
145+ // )
130146
131- return c . json ( claim )
132- } )
147+ // return c.json(claim)
148+ // })
133149
134- . get ( '/getToken' , async ( c ) => {
135- const kindeClient = await getKindeClient ( )
150+ // .get('/getToken', async (c) => {
151+ // const kindeClient = await getKindeClient()
136152
137- const accessToken = await kindeClient . getToken ( getSessionManager ( c ) )
153+ // const accessToken = await kindeClient.getToken(getSessionManager(c))
138154
139- return c . text ( accessToken )
140- } )
155+ // return c.text(accessToken)
156+ // })
0 commit comments