update saladeaul.adigitaltw

This commit is contained in:
2025-11-10 15:33:23 -03:00
parent c3f370e86c
commit 9ff11c997c
46 changed files with 302 additions and 1941 deletions

View File

@@ -1,43 +0,0 @@
import type { OAuth2Tokens } from 'arctic'
import { decodeJwt } from 'jose'
import { Authenticator } from 'remix-auth'
import { CodeChallengeMethod, OAuth2Strategy } from 'remix-auth-oauth2'
export type User = {
sub: string
email: string
name: string
scope: string
email_verified: boolean
accessToken: string
refreshToken: string
}
export function createAuth(env: Env) {
const authenticator = new Authenticator()
const strategy = new OAuth2Strategy(
{
clientId: env.CLIENT_ID,
clientSecret: env.CLIENT_SECRET,
redirectURI: env.REDIRECT_URI,
authorizationEndpoint: `${env.ISSUER_URL}/authorize`,
tokenEndpoint: `${env.ISSUER_URL}/token`,
tokenRevocationEndpoint: `${env.ISSUER_URL}/revoke`,
scopes: env.SCOPE.split(' '),
codeChallengeMethod: CodeChallengeMethod.S256
},
async ({ tokens }: { tokens: OAuth2Tokens }) => {
const user = decodeJwt(tokens.idToken())
return {
...user,
accessToken: tokens.accessToken(),
refreshToken: tokens.hasRefreshToken() ? tokens.refreshToken() : null
}
}
)
authenticator.use(strategy, 'oidc')
return authenticator
}

View File

@@ -1,7 +1,8 @@
import { userContext } from '@/context'
import type { User } from '@/lib/auth'
import type { LoaderFunctionArgs } from 'react-router'
import type { User } from '@repo/auth/auth'
import { userContext } from '@repo/auth/context'
export enum HttpMethod {
GET = 'GET',
POST = 'POST',

View File

@@ -1,15 +0,0 @@
import { createCookieSessionStorage } from 'react-router'
export function createSessionStorage(env: Env) {
const sessionStorage = createCookieSessionStorage({
cookie: {
name: '__session',
httpOnly: true,
secure: false,
secrets: [env.SESSION_SECRET],
sameSite: 'lax',
maxAge: 86400 * 7 // 7 days
}
})
return sessionStorage
}