-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.zod.ts
More file actions
102 lines (87 loc) · 3.62 KB
/
auth.zod.ts
File metadata and controls
102 lines (87 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { BaseResponseSchema } from './contract.zod';
/**
* Authentication Service Protocol
*
* Defines the standard API contracts for Identity, Session Management,
* and Access Control.
*/
// ==========================================
// Authentication Types
// ==========================================
export const AuthProvider = z.enum([
'local',
'google',
'github',
'microsoft',
'ldap',
'saml'
]);
export const SessionUserSchema = z.object({
id: z.string().describe('User ID'),
email: z.string().email().describe('Email address'),
emailVerified: z.boolean().default(false).describe('Is email verified?'),
name: z.string().describe('Display name'),
image: z.string().optional().describe('Avatar URL'),
username: z.string().optional().describe('Username (optional)'),
roles: z.array(z.string()).optional().default([]).describe('Assigned role IDs'),
tenantId: z.string().optional().describe('Current tenant ID'),
language: z.string().default('en').describe('Preferred language'),
timezone: z.string().optional().describe('Preferred timezone'),
createdAt: z.string().datetime().optional(),
updatedAt: z.string().datetime().optional(),
});
export const SessionSchema = z.object({
id: z.string(),
expiresAt: z.string().datetime(),
token: z.string().optional(),
ipAddress: z.string().optional(),
userAgent: z.string().optional(),
userId: z.string(),
});
// ==========================================
// Requests
// ==========================================
export const LoginType = z.enum(['email', 'username', 'phone', 'magic-link', 'social']);
export const LoginRequestSchema = z.object({
type: LoginType.default('email').describe('Login method'),
email: z.string().email().optional().describe('Required for email/magic-link'),
username: z.string().optional().describe('Required for username login'),
password: z.string().optional().describe('Required for password login'),
provider: z.string().optional().describe('Required for social (google, github)'),
redirectTo: z.string().optional().describe('Redirect URL after successful login'),
});
export const RegisterRequestSchema = z.object({
email: z.string().email(),
password: z.string(),
name: z.string(),
image: z.string().optional(),
});
export const RefreshTokenRequestSchema = z.object({
refreshToken: z.string().describe('Refresh token'),
});
// ==========================================
// Responses
// ==========================================
export const SessionResponseSchema = BaseResponseSchema.extend({
data: z.object({
session: SessionSchema.describe('Active Session Info'),
user: SessionUserSchema.describe('Current User Details'),
token: z.string().optional().describe('Bearer token if not using cookies'),
}),
});
export const UserProfileResponseSchema = BaseResponseSchema.extend({
data: SessionUserSchema,
});
export type AuthProvider = z.infer<typeof AuthProvider>;
export type SessionUser = z.infer<typeof SessionUserSchema>;
export type SessionUserInput = z.input<typeof SessionUserSchema>;
export type Session = z.infer<typeof SessionSchema>;
export type LoginType = z.infer<typeof LoginType>;
export type LoginRequest = z.infer<typeof LoginRequestSchema>;
export type LoginRequestInput = z.input<typeof LoginRequestSchema>;
export type RegisterRequest = z.infer<typeof RegisterRequestSchema>;
export type RefreshTokenRequest = z.infer<typeof RefreshTokenRequestSchema>;
export type SessionResponse = z.infer<typeof SessionResponseSchema>;
export type UserProfileResponse = z.infer<typeof UserProfileResponseSchema>;