(context?: SessionContext)
| 316 | * @returns the new active session |
| 317 | */ |
| 318 | export function startSession(context?: SessionContext): Session { |
| 319 | const isolationScope = getIsolationScope(); |
| 320 | |
| 321 | const { user } = getCombinedScopeData(isolationScope, getCurrentScope()); |
| 322 | |
| 323 | // Will fetch userAgent if called from browser sdk |
| 324 | const { userAgent } = GLOBAL_OBJ.navigator || {}; |
| 325 | |
| 326 | const session = makeSession({ |
| 327 | user, |
| 328 | ...(userAgent && { userAgent }), |
| 329 | ...context, |
| 330 | }); |
| 331 | |
| 332 | // End existing session if there's one |
| 333 | const currentSession = isolationScope.getSession(); |
| 334 | if (currentSession?.status === 'ok') { |
| 335 | updateSession(currentSession, { status: 'exited' }); |
| 336 | } |
| 337 | |
| 338 | endSession(); |
| 339 | |
| 340 | // Afterwards we set the new session on the scope |
| 341 | isolationScope.setSession(session); |
| 342 | |
| 343 | return session; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * End the session on the current isolation scope. |
no test coverage detected