Skip to content

Commit ce87369

Browse files
chore: wip
1 parent 1b582e0 commit ce87369

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

storage/framework/core/api/build.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { intro, outro } from '../build/src'
2-
import { dts } from './dts'
32

43
const { startTime } = await intro({
54
dir: import.meta.dir,
@@ -12,12 +11,7 @@ const result = await Bun.build({
1211
target: 'bun',
1312
sourcemap: 'linked',
1413
minify: true,
15-
plugins: [
16-
dts({
17-
root: './src',
18-
outdir: './dist',
19-
}),
20-
],
14+
plugins: [],
2115
})
2216

2317
await outro({

storage/framework/core/api/src/ofetch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ interface Params {
55
}
66

77
interface ApiFetch {
8-
get(url: string, params?: Params): Promise<FetchResponse>
9-
post(url: string, params?: Params): Promise<FetchResponse>
10-
destroy(url: string, params?: Params): Promise<FetchResponse>
11-
patch(url: string, params?: Params): Promise<FetchResponse>
12-
put(url: string, params?: Params): Promise<FetchResponse>
8+
get(url: string, params?: Params, header?: Headers): Promise<FetchResponse>
9+
post(url: string, params?: Params, header?: Headers): Promise<FetchResponse>
10+
destroy(url: string, params?: Params, header?: Headers): Promise<FetchResponse>
11+
patch(url: string, params?: Params, header?: Headers): Promise<FetchResponse>
12+
put(url: string, params?: Params, header?: Headers): Promise<FetchResponse>
1313
setToken(authToken: string): void
1414
baseURL: '/' | string
1515
loading: boolean

storage/framework/core/auth/src/authentication.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import { request } from '@stacksjs/router'
22
import { verifyHash } from '@stacksjs/security'
33
import AccessToken from '../../../orm/src/models/AccessToken'
4-
import Team from '../../../orm/src/models/Team'
4+
import Team, { type TeamModel } from '../../../orm/src/models/Team'
55
import User from '../../../orm/src/models/User'
66

77
interface Credentials {
8-
password: string | number | undefined
8+
password: string
99
[key: string]: string | number | undefined
1010
}
1111

12+
type AuthToken = `${number}:${number}:${string}`
13+
1214
const authConfig = { username: 'email', password: 'password' }
1315

1416
let authUser: any = undefined
1517

1618
export async function attempt(credentials: Credentials, remember?: boolean): Promise<boolean> {
19+
let hashCheck = false
20+
1721
const user = await User.where(authConfig.username, credentials[authConfig.username]).first()
22+
const authPass = credentials[authConfig.password]
1823

19-
const hashCheck = await verifyHash(credentials[authConfig.password], user?.password, 'bcrypt')
24+
if (typeof authPass === 'string' && user?.password) hashCheck = await verifyHash(authPass, user?.password, 'bcrypt')
2025

2126
if (hashCheck) {
2227
if (user) {
@@ -29,7 +34,7 @@ export async function attempt(credentials: Credentials, remember?: boolean): Pro
2934
return false
3035
}
3136

32-
export async function team() {
37+
export async function team(): Promise<TeamModel | undefined> {
3338
if (authUser) {
3439
const teams = await authUser.userTeams()
3540

@@ -65,8 +70,7 @@ export async function team() {
6570
return team
6671
}
6772

68-
// TODO: type this string better based on our token format
69-
export async function authToken(): Promise<string | undefined> {
73+
export async function authToken(): Promise<AuthToken | undefined> {
7074
if (authUser) {
7175
const teams = await authUser.userTeams()
7276

storage/framework/core/router/src/request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface ValidationField {
1212
message: Record<string, string>
1313
}
1414

15+
type AuthToken = `${number}:${number}:${string}`
16+
1517
interface CustomAttributes {
1618
[key: string]: ValidationField
1719
}
@@ -86,7 +88,7 @@ export class Request<T extends RequestData = RequestData> implements RequestInst
8688
return this.params ? this.params[key] || null : null
8789
}
8890

89-
public bearerToken(): string | null {
91+
public bearerToken(): string | null | AuthToken {
9092
const authorizationHeader = this.headers.get('authorization')
9193

9294
if (authorizationHeader?.startsWith('Bearer ')) {

0 commit comments

Comments
 (0)