Skip to content

Commit

Permalink
env in user app!
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Jul 1, 2024
1 parent 1622f89 commit be564f2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/firstly/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ KIT_AUTH_ADMIN = "Ermin,JYC"
# Enable GitHub login
GITHUB_CLIENT_ID = ''
GITHUB_CLIENT_SECRET = ''
GITHUB_REDIRECT_URI = 'http://localhost:5173/api/auth_callback'
# GITHUB_REDIRECT_URI = 'http://localhost:5173/api/auth_callback'
15 changes: 7 additions & 8 deletions packages/firstly/src/lib/auth/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { GitHub } from 'arctic'

import { remult } from 'remult'

import { env } from '$env/dynamic/private'

import { checkOAuthConfig } from '.'
import { logAuth, type KitOAuth2Provider } from '../'

Expand All @@ -24,18 +22,18 @@ import { logAuth, type KitOAuth2Provider } from '../'
* _FYI: GITHUB_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
*/
export function github(options?: {
clientID?: string
secret?: string
redirectURI?: string
GITHUB_CLIENT_ID: string
GITHUB_CLIENT_SECRET: string
GITHUB_REDIRECT_URI?: string
authorizationURLOptions?: ReturnType<
KitOAuth2Provider<'github', GitHub>['authorizationURLOptions']
>
log?: boolean
}): KitOAuth2Provider<'github', GitHub> {
const name = 'github'

const clientID = options?.clientID ?? env.GITHUB_CLIENT_ID ?? ''
const secret = options?.secret ?? env.GITHUB_CLIENT_SECRET ?? ''
const clientID = options?.GITHUB_CLIENT_ID ?? ''
const secret = options?.GITHUB_CLIENT_SECRET ?? ''

const urlForKeys = 'https://github.com/settings/developers'
checkOAuthConfig(name, clientID, secret, urlForKeys, false)
Expand All @@ -44,7 +42,8 @@ export function github(options?: {
name,
isPKCE: false,
getArcticProvider: () => {
const redirectURI = options?.redirectURI || `${remult.context.url.origin}/api/auth_callback`
const redirectURI =
options?.GITHUB_REDIRECT_URI || `${remult.context.url.origin}/api/auth_callback`

checkOAuthConfig(name, clientID, secret, urlForKeys, true)

Expand Down
3 changes: 1 addition & 2 deletions packages/firstly/src/lib/auth/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { cyan, gray, green, italic, yellow } from '@kitql/helpers'

import { mask } from '$lib/formats/strings'

import { logAuth } from '..'
import { mask } from '../../formats/strings'

export const checkOAuthConfig = (
name: string,
Expand Down
15 changes: 7 additions & 8 deletions packages/firstly/src/lib/auth/providers/strava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Strava } from 'arctic'

import { remult } from 'remult'

import { env } from '$env/dynamic/private'

import { checkOAuthConfig } from '.'
import { logAuth, type KitOAuth2Provider } from '../'

Expand All @@ -24,18 +22,18 @@ import { logAuth, type KitOAuth2Provider } from '../'
* _FYI: STRAVA_REDIRECT_URI is optional as auth module will default to "${origin}/api/auth_callback"._
*/
export function strava(options?: {
clientID: string
secret: string
redirectURI?: string
STRAVA_CLIENT_ID: string
STRAVA_CLIENT_SECRET: string
STRAVA_REDIRECT_URI?: string
authorizationURLOptions?: ReturnType<
KitOAuth2Provider<'strava', Strava>['authorizationURLOptions']
>
log?: boolean
}): KitOAuth2Provider<'strava', Strava> {
const name = 'strava'

const clientID = options?.clientID ?? env.GITHUB_CLIENT_ID ?? ''
const secret = options?.secret ?? env.GITHUB_CLIENT_SECRET ?? ''
const clientID = options?.STRAVA_CLIENT_ID ?? ''
const secret = options?.STRAVA_CLIENT_SECRET ?? ''

const urlForKeys = 'https://www.strava.com/settings/api'
checkOAuthConfig(name, clientID, secret, urlForKeys, false)
Expand All @@ -44,7 +42,8 @@ export function strava(options?: {
name,
isPKCE: false,
getArcticProvider: () => {
const redirectURI = options?.redirectURI || `${remult.context.url.origin}/api/auth_callback`
const redirectURI =
options?.STRAVA_REDIRECT_URI || `${remult.context.url.origin}/api/auth_callback`
checkOAuthConfig(name, clientID, secret, urlForKeys, true)
return new Strava(clientID, secret, redirectURI)
},
Expand Down
3 changes: 2 additions & 1 deletion packages/firstly/src/lib/bin/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ GITHUB_CLIENT_SECRET = ''
`import { firstly } from 'firstly/api'
import { auth } from 'firstly/auth'
// import { github } from 'firstly/auth/providers'
// import { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } from '$env/static/private'
import { Log } from '@kitql/helpers'
import { tasks } from './modules/tasks'
Expand Down Expand Up @@ -155,7 +156,7 @@ export const api = firstly({
// async function oauth() {
// window.location.href = await AuthController.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
// }
// github()
// github( { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } )
],
},
}),
Expand Down

0 comments on commit be564f2

Please sign in to comment.