You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/StytchCore/SharedModels/SessionToken.swift
+3-53Lines changed: 3 additions & 53 deletions
Original file line number
Diff line number
Diff line change
@@ -1,67 +1,17 @@
1
1
import Foundation
2
2
3
-
// TODO: include optional expiration here
4
-
/// Represents one of two kinds of tokens used to represent a session (see ``SessionToken/Kind-swift.enum``, for more info.) These tokens are used to authenticate the current user/member.
5
-
publicstructSessionToken:Equatable,Sendable{
6
-
/// A type representing the different kinds of session tokens available.
7
-
publicenumKind:CaseIterable,Sendable{
8
-
/// An token which is an opaque string, simply representing the session.
9
-
case opaque
10
-
/// A JWT representing the session, which contains signed and serialized information about the session.
11
-
case jwt
12
-
13
-
varname:String{
14
-
switchself{
15
-
case.opaque:
16
-
return"stytch_session"
17
-
case.jwt:
18
-
return"stytch_session_jwt"
19
-
}
20
-
}
21
-
}
22
-
23
-
/// The kind of session token.
24
-
publicletkind:Kind
25
-
26
-
/// The string value of the session token.
27
-
publicletvalue:String
28
-
29
-
varname:String{ kind.name }
30
-
31
-
privateinit(kind:Kind, value:String){
32
-
self.kind = kind
33
-
self.value = value
34
-
}
35
-
36
-
/// Initializes a new token and marks it as a JWT.
37
-
publicstaticfunc jwt(_ value:String)->Self{
38
-
.init(kind:.jwt, value: value)
39
-
}
40
-
41
-
/// Initializes a new token and marks it as an opaque token.
42
-
publicstaticfunc opaque(_ value:String)->Self{
43
-
.init(kind:.opaque, value: value)
44
-
}
45
-
}
3
+
publictypealiasSessionToken=String
46
4
47
5
/// A public interface to require the caller to explicitly pass one of each type of non nil token in order to update a session.
48
6
publicstructSessionTokens:Sendable{
49
7
internalletjwt:SessionToken?
50
8
internalletopaque:SessionToken
51
9
52
-
/// A nullable initializer that requires the caller to pass at least one non-nil instance of each token type.
10
+
/// An initializer that requires the caller to pass a nonnil opaque SessionToken and an optional jwt.
53
11
/// - Parameters:
54
12
/// - jwt: An instance of `SessionToken` with a `type` of `.jwt`
55
13
/// - opaque: An instance of `SessionToken` with a `type` of `.opaque`
0 commit comments